{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c7ef7bc5",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# pandas数据结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9ebe82b1",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b41f77f",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "## Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "63f138d7",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       0.0\n",
       "1       1.0\n",
       "2       7.0\n",
       "3       9.0\n",
       "4       NaN\n",
       "5       NaN\n",
       "6    1024.0\n",
       "7     512.0\n",
       "dtype: float64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "a       0.0\n",
       "b       1.0\n",
       "c       7.0\n",
       "d       9.0\n",
       "e       NaN\n",
       "f       NaN\n",
       "h    1024.0\n",
       "i     512.0\n",
       "dtype: float32"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "a     99\n",
       "b    137\n",
       "c    149\n",
       "Name: Python_score, dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ll = [0,1,7,9,np.NAN,None,1024,512] # 无论是numpy中的NAN还是Python中的None在pandas中都以缺失数据NaN对待\n",
    "ll\n",
    "s1 = pd.Series(data = ll) # pandas自动添加索引\n",
    "s2 = pd.Series(data = ll,index = list('abcdefhi'),dtype='float32') # 指定行索引\n",
    "# 传入字典创建，key行索引\n",
    "s3 = pd.Series(data = {'a':99,'b':137,'c':149},name = 'Python_score')\n",
    "display(s1,s2,s3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f24b0d0",
   "metadata": {
    "hidden": true
   },
   "source": [
    "Series\n",
    "l = np.array([1,2,3,6,9])\n",
    "\n",
    "s1 = pd.Series(data = l) #Series是一维的数组，和NumPy数组不一样：Series多了索引\n",
    "display(l,s1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5dfca9ce",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1\n",
       "B    2\n",
       "C    3\n",
       "D    6\n",
       "E    9\n",
       "dtype: int32"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = pd.Series(data = l,index = list('ABCDE'))\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5e5fb9d1",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    149\n",
       "B    130\n",
       "C    118\n",
       "D     99\n",
       "E     66\n",
       "dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3 = pd.Series(data={'A':149,'B':130,'C':118,'D':99,'E':66})\n",
    "s3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5ee81f3",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "## DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b37a2427",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>29</td>\n",
       "      <td>44</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>124</td>\n",
       "      <td>148</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>80</td>\n",
       "      <td>103</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>59</td>\n",
       "      <td>140</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>124</td>\n",
       "      <td>120</td>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>73</td>\n",
       "      <td>22</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>119</td>\n",
       "      <td>77</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>97</td>\n",
       "      <td>24</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>110</td>\n",
       "      <td>10</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>15</td>\n",
       "      <td>125</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Math   En\n",
       "A      29    44  137\n",
       "B     124   148   19\n",
       "C      80   103   25\n",
       "D      59   140  132\n",
       "E     124   120  108\n",
       "F      73    22  132\n",
       "H     119    77   21\n",
       "I      97    24  135\n",
       "J     110    10   64\n",
       "K      15   125   18"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Series是一维的，功能比较少\n",
    "#DataFrame是二维的，多个Series共用索引，组成了DataFrame\n",
    "df1 = pd.DataFrame(data = np.random.randint(0,151,size=(10,3)),\n",
    "                   index = list('ABCDEFHIJK'), #行索引\n",
    "                   columns=['Python','Math','En']) #列索引\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ed7ae5b1",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>66</td>\n",
       "      <td>88</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>99</td>\n",
       "      <td>65</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>128</td>\n",
       "      <td>137</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Math   En\n",
       "0      66    88  100\n",
       "1      99    65  121\n",
       "2     128   137   45"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.DataFrame(data = {'Python':[66,99,128],'Math':[88,65,137],'En':[100,121,45]})\n",
    "df2 #字典，key作为列索引，不指定index默认从0开始索引，自动索引一样\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "232b78fb",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>99</td>\n",
       "      <td>111</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>李四</th>\n",
       "      <td>107</td>\n",
       "      <td>137</td>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Michael</th>\n",
       "      <td>122</td>\n",
       "      <td>88</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Python  Math   En\n",
       "张三           99   111   68\n",
       "李四          107   137  108\n",
       "Michael     122    88   43"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# index 作为行索引，字典中的key作为列索引，创建了3*3的DataFrame表格二维数组\n",
    "df3 = pd.DataFrame(data = {'Python':[99,107,122],'Math':[111,137,88],'En':[68,108,43]},# key作为列索引\n",
    "index = ['张三','李四','Michael']) # 行索引\n",
    "df3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "611f4fc8",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数据查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5f926bbf",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>71</td>\n",
       "      <td>63</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>28</td>\n",
       "      <td>122</td>\n",
       "      <td>125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74</td>\n",
       "      <td>148</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>146</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>145</td>\n",
       "      <td>62</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>79</td>\n",
       "      <td>31</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>127</td>\n",
       "      <td>108</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>116</td>\n",
       "      <td>123</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>39</td>\n",
       "      <td>62</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Math   En\n",
       "0       71    63  101\n",
       "1       28   122  125\n",
       "2       74   148   24\n",
       "3        4   146   55\n",
       "4      145    62  142\n",
       "..     ...   ...  ...\n",
       "95      79    31   52\n",
       "96     127   108   67\n",
       "97     120    80   78\n",
       "98     116   123   10\n",
       "99      39    62   77\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "df = pd.DataFrame(data = np.random.randint(0,151,size = (100,3)),\n",
    "                  index = None,# 行索引默认\n",
    "                  columns = ['Python','Math','En'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8909cffc",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 3)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape #查看DataFrame形状"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9ebb26cf",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>149</td>\n",
       "      <td>112</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>52</td>\n",
       "      <td>125</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>83</td>\n",
       "      <td>150</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Math   En\n",
       "0     149   112  117\n",
       "1      52   125   99\n",
       "2      83   150  114"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(n = 3) #显示前N个，默认N=5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2e871f0c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>144</td>\n",
       "      <td>113</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0</td>\n",
       "      <td>79</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>103</td>\n",
       "      <td>9</td>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>144</td>\n",
       "      <td>51</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Math   En\n",
       "95     144   113   54\n",
       "96       0    79   89\n",
       "97      63     6  119\n",
       "98     103     9  148\n",
       "99     144    51   94"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail() #显示后n个，默认显示5个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "26367114",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python    int32\n",
       "Math      int32\n",
       "En        int32\n",
       "dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes # 数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "246794f6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 100 entries, 0 to 99\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype\n",
      "---  ------  --------------  -----\n",
      " 0   Python  100 non-null    int32\n",
      " 1   Math    100 non-null    int32\n",
      " 2   En      100 non-null    int32\n",
      "dtypes: int32(3)\n",
      "memory usage: 1.3 KB\n"
     ]
    }
   ],
   "source": [
    "df.info() #信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "909c5d70",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>100.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>100.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>83.450000</td>\n",
       "      <td>77.570000</td>\n",
       "      <td>74.090000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>40.829623</td>\n",
       "      <td>42.586159</td>\n",
       "      <td>42.825956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>53.750000</td>\n",
       "      <td>43.500000</td>\n",
       "      <td>37.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>87.500000</td>\n",
       "      <td>77.500000</td>\n",
       "      <td>76.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>117.250000</td>\n",
       "      <td>113.000000</td>\n",
       "      <td>108.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>149.000000</td>\n",
       "      <td>150.000000</td>\n",
       "      <td>149.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Python        Math          En\n",
       "count  100.000000  100.000000  100.000000\n",
       "mean    83.450000   77.570000   74.090000\n",
       "std     40.829623   42.586159   42.825956\n",
       "min      0.000000    2.000000    0.000000\n",
       "25%     53.750000   43.500000   37.000000\n",
       "50%     87.500000   77.500000   76.500000\n",
       "75%    117.250000  113.000000  108.000000\n",
       "max    149.000000  150.000000  149.000000"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe() # 描述：平均值、标准差、中位数、 四等分、最大值 、最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "851c5fbc",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 71,  63, 101],\n",
       "       [ 28, 122, 125],\n",
       "       [ 74, 148,  24],\n",
       "       [  4, 146,  55],\n",
       "       [145,  62, 142],\n",
       "       [ 71,  13,  53],\n",
       "       [143, 139,  59],\n",
       "       [  6,  37,  31],\n",
       "       [ 42, 144,  75],\n",
       "       [ 21, 138, 113],\n",
       "       [118,   0,  37],\n",
       "       [  3, 146, 134],\n",
       "       [ 64,  88,  84],\n",
       "       [137, 133,  60],\n",
       "       [ 76, 135, 146],\n",
       "       [ 99,  79,  51],\n",
       "       [ 80, 120,  58],\n",
       "       [133,  85, 117],\n",
       "       [ 93,  22,  61],\n",
       "       [ 96,  18, 145],\n",
       "       [102,  48, 119],\n",
       "       [105,  27,  55],\n",
       "       [ 53,  99,  70],\n",
       "       [150, 106,  18],\n",
       "       [ 55,  10, 124],\n",
       "       [ 80,  34, 133],\n",
       "       [ 26,   4,  90],\n",
       "       [114,  71,  79],\n",
       "       [134, 128,   3],\n",
       "       [132,  55,   6],\n",
       "       [ 35, 100, 124],\n",
       "       [ 22,  17,  28],\n",
       "       [ 81, 138,  20],\n",
       "       [102,  80,  73],\n",
       "       [ 16,  90,  23],\n",
       "       [ 23,  26,  25],\n",
       "       [ 49,  27,  48],\n",
       "       [ 52,  44, 132],\n",
       "       [114,  57, 124],\n",
       "       [ 48,   7,  27],\n",
       "       [ 37, 126, 119],\n",
       "       [134,  36,  35],\n",
       "       [  1, 136,  72],\n",
       "       [ 46,  25,   9],\n",
       "       [ 49,  87,  91],\n",
       "       [ 56,  85,  69],\n",
       "       [ 70,  97,  49],\n",
       "       [ 35,   8, 114],\n",
       "       [ 58,  34,  75],\n",
       "       [145, 125,  77],\n",
       "       [139,  28,  46],\n",
       "       [129,  42,  68],\n",
       "       [115,  60, 105],\n",
       "       [109,   4,  88],\n",
       "       [122,   7, 103],\n",
       "       [ 38, 132,  36],\n",
       "       [141,  72,  52],\n",
       "       [  6, 100, 125],\n",
       "       [ 80,  28,  51],\n",
       "       [ 74,  15,   4],\n",
       "       [145,  59,  33],\n",
       "       [ 63,   3,  38],\n",
       "       [ 69,  50, 107],\n",
       "       [ 25,  63,  38],\n",
       "       [ 33, 102,  80],\n",
       "       [  8, 114,  27],\n",
       "       [ 24, 104,  72],\n",
       "       [ 60,  63, 130],\n",
       "       [104,  78,  66],\n",
       "       [132,  98,  28],\n",
       "       [ 50,  80,  63],\n",
       "       [ 43, 105,  51],\n",
       "       [100,  69, 124],\n",
       "       [ 21,  96,  45],\n",
       "       [ 86,  77, 149],\n",
       "       [  6,   5,  18],\n",
       "       [ 57,  61,  82],\n",
       "       [120, 114,  37],\n",
       "       [136,  74,  81],\n",
       "       [112,  26,  47],\n",
       "       [114,  72, 101],\n",
       "       [ 47,  22,  27],\n",
       "       [ 98,  11,  10],\n",
       "       [ 36,  80, 115],\n",
       "       [ 96,  82,  83],\n",
       "       [ 84, 120,  65],\n",
       "       [ 34,  24,  98],\n",
       "       [147,  91, 141],\n",
       "       [115,  50,  77],\n",
       "       [133,  86, 142],\n",
       "       [ 85,  47,   0],\n",
       "       [ 75,   2,  67],\n",
       "       [ 95,  32,  12],\n",
       "       [ 42,   4,  83],\n",
       "       [ 62,   2,  73],\n",
       "       [ 79,  31,  52],\n",
       "       [127, 108,  67],\n",
       "       [120,  80,  78],\n",
       "       [116, 123,  10],\n",
       "       [ 39,  62,  77]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values #值，返回的是NumPy数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9ac22f40",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Python', 'Math', 'En'], dtype='object')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns #列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f0c91bc4",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=100, step=1)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index #行索引0-99"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33ff7a6d",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数据的输入与输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cbc6827",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4ebaa00d",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>74</td>\n",
       "      <td>41</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>69</td>\n",
       "      <td>88</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>97</td>\n",
       "      <td>70</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>19</td>\n",
       "      <td>150</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>146</td>\n",
       "      <td>32</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>64</td>\n",
       "      <td>80</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>106</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>150</td>\n",
       "      <td>95</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>57</td>\n",
       "      <td>110</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Math   En\n",
       "0       74    41   42\n",
       "1        6    51   89\n",
       "2       69    88   35\n",
       "3       97    70  138\n",
       "4       19   150   74\n",
       "..     ...   ...  ...\n",
       "95     146    32   14\n",
       "96      64    80  137\n",
       "97     106   102   43\n",
       "98     150    95  122\n",
       "99      57   110   62\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,151,size = [100,3]),\n",
    "                                          columns = ['Python','Math','En'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d92dc29f",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>74</td>\n",
       "      <td>41</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>69</td>\n",
       "      <td>88</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>97</td>\n",
       "      <td>70</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>19</td>\n",
       "      <td>150</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>146</td>\n",
       "      <td>32</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>64</td>\n",
       "      <td>80</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>106</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>150</td>\n",
       "      <td>95</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>57</td>\n",
       "      <td>110</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Math   En\n",
       "0       74    41   42\n",
       "1        6    51   89\n",
       "2       69    88   35\n",
       "3       97    70  138\n",
       "4       19   150   74\n",
       "..     ...   ...  ...\n",
       "95     146    32   14\n",
       "96      64    80  137\n",
       "97     106   102   43\n",
       "98     150    95  122\n",
       "99      57   110   62\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.to_csv('./data.csv',\n",
    "          sep =';',# 文本分隔符，默认是逗号\n",
    "         index = True, #保存行索引\n",
    "          header = True) #保存列索引\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d1d1efb0",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "df.to_csv('./data2.csv',sep =',',\n",
    "         index = False, #保存行索引\n",
    "          header = False) #保存列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4d303726",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>10</th>\n",
       "      <th>84</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>64</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>144</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>40</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>141</td>\n",
       "      <td>127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>45</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>40</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>143</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>49</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>7</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>99 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      10   84\n",
       "136          \n",
       "129   64   34\n",
       "62   144  114\n",
       "140   40  135\n",
       "74     2    3\n",
       "128  141  127\n",
       "..   ...  ...\n",
       "142   45   10\n",
       "99    40   89\n",
       "80   143   98\n",
       "19    49   44\n",
       "21     7  132\n",
       "\n",
       "[99 rows x 2 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table('./data2.csv', # 和read_csv类似，读取限定分隔符的文本文件\n",
    "sep = ',',\n",
    "header = [0],#指定列索引\n",
    "index_col=1) # 指定行索引,IT作为行索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "14d0b70a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Math</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>74</td>\n",
       "      <td>41</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>69</td>\n",
       "      <td>88</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>97</td>\n",
       "      <td>70</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>19</td>\n",
       "      <td>150</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>146</td>\n",
       "      <td>32</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>64</td>\n",
       "      <td>80</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>106</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>150</td>\n",
       "      <td>95</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>57</td>\n",
       "      <td>110</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Math   En\n",
       "0       74    41   42\n",
       "1        6    51   89\n",
       "2       69    88   35\n",
       "3       97    70  138\n",
       "4       19   150   74\n",
       "..     ...   ...  ...\n",
       "95     146    32   14\n",
       "96      64    80  137\n",
       "97     106   102   43\n",
       "98     150    95  122\n",
       "99      57   110   62\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('./data.csv',\n",
    "sep = ';',# 默认是逗号\n",
    "header = [0],#指定列索引\n",
    "index_col=0) # 指定行索引\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ac05e8ad",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>Python</th>\n",
       "      <th>En</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Math</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>0</td>\n",
       "      <td>74</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>2</td>\n",
       "      <td>69</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>3</td>\n",
       "      <td>97</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>4</td>\n",
       "      <td>19</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>95</td>\n",
       "      <td>146</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>96</td>\n",
       "      <td>64</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>97</td>\n",
       "      <td>106</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>98</td>\n",
       "      <td>150</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>99</td>\n",
       "      <td>57</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0  Python   En\n",
       "Math                         \n",
       "41             0      74   42\n",
       "51             1       6   89\n",
       "88             2      69   35\n",
       "70             3      97  138\n",
       "150            4      19   74\n",
       "...          ...     ...  ...\n",
       "32            95     146   14\n",
       "80            96      64  137\n",
       "102           97     106   43\n",
       "95            98     150  122\n",
       "110           99      57   62\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('./data.csv',\n",
    "            sep = ';',# 默认是逗号\n",
    "            index_col=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3689fd8e",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>136</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>64</td>\n",
       "      <td>129</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>144</td>\n",
       "      <td>62</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>40</td>\n",
       "      <td>140</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>74</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>45</td>\n",
       "      <td>142</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>40</td>\n",
       "      <td>99</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>143</td>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>49</td>\n",
       "      <td>19</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>7</td>\n",
       "      <td>21</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      0    1    2\n",
       "0    10  136   84\n",
       "1    64  129   34\n",
       "2   144   62  114\n",
       "3    40  140  135\n",
       "4     2   74    3\n",
       "..  ...  ...  ...\n",
       "95   45  142   10\n",
       "96   40   99   89\n",
       "97  143   80   98\n",
       "98   49   19   44\n",
       "99    7   21  132\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('./data2.csv',header = None)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86739d0c",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## Excel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "48ce4afa",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0d23a015",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lenovo\\AppData\\Local\\Temp/ipykernel_70584/3066759610.py:10: FutureWarning: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas. This is the only engine in pandas that supports writing in the xls format. Install openpyxl and write to an xlsx file instead. You can set the option io.excel.xls.writer to 'xlwt' to silence this warning. While this option is deprecated and will also raise a warning, it can be globally set and the warning suppressed.\n",
      "  df1.to_excel('./salary.xls',\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>41</td>\n",
       "      <td>31</td>\n",
       "      <td>39</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>30</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>30</td>\n",
       "      <td>42</td>\n",
       "      <td>29</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>40</td>\n",
       "      <td>21</td>\n",
       "      <td>8</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>48</td>\n",
       "      <td>43</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>49</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23</td>\n",
       "      <td>2</td>\n",
       "      <td>45</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>31</td>\n",
       "      <td>45</td>\n",
       "      <td>45</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>29</td>\n",
       "      <td>32</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>17</td>\n",
       "      <td>42</td>\n",
       "      <td>40</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2</td>\n",
       "      <td>30</td>\n",
       "      <td>38</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>39</td>\n",
       "      <td>20</td>\n",
       "      <td>18</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>10</td>\n",
       "      <td>36</td>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>27</td>\n",
       "      <td>32</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>4</td>\n",
       "      <td>22</td>\n",
       "      <td>35</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>39</td>\n",
       "      <td>8</td>\n",
       "      <td>48</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>22</td>\n",
       "      <td>34</td>\n",
       "      <td>20</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>19</td>\n",
       "      <td>38</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>13</td>\n",
       "      <td>44</td>\n",
       "      <td>31</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>38</td>\n",
       "      <td>13</td>\n",
       "      <td>38</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>2</td>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>40</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>3</td>\n",
       "      <td>20</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>13</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>36</td>\n",
       "      <td>34</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>25</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>42</td>\n",
       "      <td>46</td>\n",
       "      <td>45</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>29</td>\n",
       "      <td>47</td>\n",
       "      <td>5</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>8</td>\n",
       "      <td>14</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>16</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>46</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>44</td>\n",
       "      <td>12</td>\n",
       "      <td>40</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>26</td>\n",
       "      <td>46</td>\n",
       "      <td>1</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>22</td>\n",
       "      <td>48</td>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>6</td>\n",
       "      <td>48</td>\n",
       "      <td>27</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "      <td>49</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>26</td>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "      <td>5</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>49</td>\n",
       "      <td>45</td>\n",
       "      <td>17</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>23</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>10</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>44</td>\n",
       "      <td>28</td>\n",
       "      <td>40</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>39</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>46</td>\n",
       "      <td>28</td>\n",
       "      <td>25</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A   C   D   E\n",
       "B                 \n",
       "34  41  31  39  11\n",
       "6   30  38  40  19\n",
       "1    7  31   8  27\n",
       "28  30  42  29  44\n",
       "12  40  21   8  49\n",
       "47  48  43  11   0\n",
       "4   49  40   0  25\n",
       "5   23   2  45  10\n",
       "16  31  45  45  24\n",
       "0   29  32   4   8\n",
       "20  17  42  40  19\n",
       "22   2  30  38  26\n",
       "14  39  20  18  23\n",
       "40  10  36  23  11\n",
       "48  27  32   3  17\n",
       "39   4  22  35  44\n",
       "21   3  10   3  45\n",
       "23  39   8  48  12\n",
       "1   13   1  10  18\n",
       "23  22  34  20  30\n",
       "37  19  38   7   3\n",
       "49  13  44  31  43\n",
       "43  38  13  38  43\n",
       "45   2  27  27  16\n",
       "36  40  33   0  46\n",
       "46   3  20  40   6\n",
       "48  11   4  13   4\n",
       "29  36  34  48  48\n",
       "46  25  12   4  45\n",
       "15  42  46  45  28\n",
       "35  29  47   5  39\n",
       "15  15   8  14  30\n",
       "37  16   5   5  11\n",
       "23  46   2  36  46\n",
       "41  44  12  40  23\n",
       "16  26  46   1  47\n",
       "34  22  48  22  11\n",
       "10   6  48  27  31\n",
       "7   16   4  49   6\n",
       "1   40   0  26  13\n",
       "1   22  27  14   4\n",
       "30  26   1  29   9\n",
       "17  35  45   5  21\n",
       "12  49  45  17   3\n",
       "16  21  21   4  24\n",
       "45  23  15  15  26\n",
       "36  35  31  10  37\n",
       "21  44  28  40  10\n",
       "12  20   2  39  43\n",
       "46  46  28  25  40"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.DataFrame(data = np.random.randint(0,50,size = [50,5]), # 薪资情况\n",
    "                columns=['IT','化工','生物','教师','士兵'])\n",
    "\n",
    "df1\n",
    "\n",
    "df2 = pd.DataFrame(data = np.random.randint(0,50,size = [150,3]),# 计算机科目的考试成绩\n",
    "                columns=['Python','test.xlsnsorflow','Keras'])\n",
    "df2\n",
    "\n",
    "df1.to_excel('./salary.xls',\n",
    "sheet_name = 'salary',# Excel中工作表的名字\n",
    "header = True,# 是否保存列索引\n",
    "index = False) # 是否保存行索引，保存行索引\n",
    "\n",
    "pd.read_excel('./salary.xls',\n",
    "sheet_name=0,# 读取哪一个Excel中工作表，默认第一个\n",
    "header = 0,# 使用第一行数据作为列索引\n",
    "names = list('ABCDE'),# 替换行索引\n",
    "index_col=1)# 指定行索引，B作为行索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2e81fb18",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>IT</th>\n",
       "      <th>化工</th>\n",
       "      <th>生物</th>\n",
       "      <th>教师</th>\n",
       "      <th>士兵</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>41</td>\n",
       "      <td>34</td>\n",
       "      <td>31</td>\n",
       "      <td>39</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>30</td>\n",
       "      <td>28</td>\n",
       "      <td>42</td>\n",
       "      <td>29</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>40</td>\n",
       "      <td>12</td>\n",
       "      <td>21</td>\n",
       "      <td>8</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48</td>\n",
       "      <td>47</td>\n",
       "      <td>43</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>49</td>\n",
       "      <td>4</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>23</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>45</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>31</td>\n",
       "      <td>16</td>\n",
       "      <td>45</td>\n",
       "      <td>45</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>32</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>17</td>\n",
       "      <td>20</td>\n",
       "      <td>42</td>\n",
       "      <td>40</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "      <td>38</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>39</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>18</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>10</td>\n",
       "      <td>40</td>\n",
       "      <td>36</td>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>27</td>\n",
       "      <td>48</td>\n",
       "      <td>32</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>4</td>\n",
       "      <td>39</td>\n",
       "      <td>22</td>\n",
       "      <td>35</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>3</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>39</td>\n",
       "      <td>23</td>\n",
       "      <td>8</td>\n",
       "      <td>48</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>22</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>20</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>19</td>\n",
       "      <td>37</td>\n",
       "      <td>38</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>13</td>\n",
       "      <td>49</td>\n",
       "      <td>44</td>\n",
       "      <td>31</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>38</td>\n",
       "      <td>43</td>\n",
       "      <td>13</td>\n",
       "      <td>38</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2</td>\n",
       "      <td>45</td>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>40</td>\n",
       "      <td>36</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>3</td>\n",
       "      <td>46</td>\n",
       "      <td>20</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>11</td>\n",
       "      <td>48</td>\n",
       "      <td>4</td>\n",
       "      <td>13</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>36</td>\n",
       "      <td>29</td>\n",
       "      <td>34</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>25</td>\n",
       "      <td>46</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>42</td>\n",
       "      <td>15</td>\n",
       "      <td>46</td>\n",
       "      <td>45</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>29</td>\n",
       "      <td>35</td>\n",
       "      <td>47</td>\n",
       "      <td>5</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>8</td>\n",
       "      <td>14</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>16</td>\n",
       "      <td>37</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>46</td>\n",
       "      <td>23</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>44</td>\n",
       "      <td>41</td>\n",
       "      <td>12</td>\n",
       "      <td>40</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>26</td>\n",
       "      <td>16</td>\n",
       "      <td>46</td>\n",
       "      <td>1</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>22</td>\n",
       "      <td>34</td>\n",
       "      <td>48</td>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>48</td>\n",
       "      <td>27</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>16</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>49</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "      <td>27</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>26</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>35</td>\n",
       "      <td>17</td>\n",
       "      <td>45</td>\n",
       "      <td>5</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>49</td>\n",
       "      <td>12</td>\n",
       "      <td>45</td>\n",
       "      <td>17</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>21</td>\n",
       "      <td>16</td>\n",
       "      <td>21</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>23</td>\n",
       "      <td>45</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>35</td>\n",
       "      <td>36</td>\n",
       "      <td>31</td>\n",
       "      <td>10</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>44</td>\n",
       "      <td>21</td>\n",
       "      <td>28</td>\n",
       "      <td>40</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>20</td>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "      <td>39</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>46</td>\n",
       "      <td>46</td>\n",
       "      <td>28</td>\n",
       "      <td>25</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    IT  化工  生物  教师  士兵\n",
       "0   41  34  31  39  11\n",
       "1   30   6  38  40  19\n",
       "2    7   1  31   8  27\n",
       "3   30  28  42  29  44\n",
       "4   40  12  21   8  49\n",
       "5   48  47  43  11   0\n",
       "6   49   4  40   0  25\n",
       "7   23   5   2  45  10\n",
       "8   31  16  45  45  24\n",
       "9   29   0  32   4   8\n",
       "10  17  20  42  40  19\n",
       "11   2  22  30  38  26\n",
       "12  39  14  20  18  23\n",
       "13  10  40  36  23  11\n",
       "14  27  48  32   3  17\n",
       "15   4  39  22  35  44\n",
       "16   3  21  10   3  45\n",
       "17  39  23   8  48  12\n",
       "18  13   1   1  10  18\n",
       "19  22  23  34  20  30\n",
       "20  19  37  38   7   3\n",
       "21  13  49  44  31  43\n",
       "22  38  43  13  38  43\n",
       "23   2  45  27  27  16\n",
       "24  40  36  33   0  46\n",
       "25   3  46  20  40   6\n",
       "26  11  48   4  13   4\n",
       "27  36  29  34  48  48\n",
       "28  25  46  12   4  45\n",
       "29  42  15  46  45  28\n",
       "30  29  35  47   5  39\n",
       "31  15  15   8  14  30\n",
       "32  16  37   5   5  11\n",
       "33  46  23   2  36  46\n",
       "34  44  41  12  40  23\n",
       "35  26  16  46   1  47\n",
       "36  22  34  48  22  11\n",
       "37   6  10  48  27  31\n",
       "38  16   7   4  49   6\n",
       "39  40   1   0  26  13\n",
       "40  22   1  27  14   4\n",
       "41  26  30   1  29   9\n",
       "42  35  17  45   5  21\n",
       "43  49  12  45  17   3\n",
       "44  21  16  21   4  24\n",
       "45  23  45  15  15  26\n",
       "46  35  36  31  10  37\n",
       "47  44  21  28  40  10\n",
       "48  20  12   2  39  43\n",
       "49  46  46  28  25  40"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with pd.ExcelWriter('./data.xlsx') as writer:\n",
    "        df1.to_excel(writer,sheet_name='salary',index = False)\n",
    "        df2.to_excel(writer,sheet_name='score',index = False)\n",
    "pd.read_excel('./data.xlsx',sheet_name='salary') # 读取Excel中指定名字的工作表\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e33a40e8",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33ae63e8",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "293f3870",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "0de9fff4",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "## HDF5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c91b46da",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>16</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2</td>\n",
       "      <td>46</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>5</td>\n",
       "      <td>41</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>6</td>\n",
       "      <td>43</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>7</td>\n",
       "      <td>17</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        index  Tensorflow  Keras\n",
       "Python                          \n",
       "49          0          21     39\n",
       "1           1          16     46\n",
       "27          2          46     25\n",
       "33          3          23     43\n",
       "33          4          10     29\n",
       "14          5          41     20\n",
       "19          6          43     27\n",
       "30          7          17     15\n",
       "20          8           3     47\n",
       "36          9           5     46"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# SQLAlchemy是Python编程语言下的一款开源软件。提供了SQL工具包及对象关系映射（ORM）工具\n",
    "from sqlalchemy import create_engine\n",
    "df = pd.DataFrame(data = np.random.randint(0,50,size = [150,3]),# 计算机科目的考试成绩\n",
    "            columns=['Python','Tensorflow','Keras'])\n",
    "# 数据库连接\n",
    "conn = create_engine('mysql+pymysql://root:root@localhost/test?charset=UTF8MB4')\n",
    "# 保存到数据库\n",
    "df.to_sql('score',#数据库中表名\n",
    "        conn,# 数据库连接\n",
    "        if_exists='append')#如果表名存在，追加数据\n",
    "# 从数据库中加载\n",
    "pd.read_sql('select * from score limit 10', # sql查询语句\n",
    "            conn, # 数据库连接\n",
    "            index_col='Python') # 指定行索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ed84767",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c349d701",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "596498e0",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8418acc1",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "## SQL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ca48c920",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "from sqlalchemy import create_engine #数据库引擎，构建和数据库的连接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f4250be0",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "# PyMySQL\n",
    "# 类似网页地址\n",
    "engine = create_engine('mysql+pymysql://root:root@localhost/test')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed404d97",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ee55c45",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03225963",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec79fecd",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4cdb8031",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas数据选取"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2a92a2d",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "### 第一节 字段数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "62771fc9",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>88</td>\n",
       "      <td>149</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>133</td>\n",
       "      <td>39</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>48</td>\n",
       "      <td>75</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>144</td>\n",
       "      <td>69</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>21</td>\n",
       "      <td>56</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>87</td>\n",
       "      <td>138</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>53</td>\n",
       "      <td>12</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>88</td>\n",
       "      <td>43</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>111</td>\n",
       "      <td>96</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>117</td>\n",
       "      <td>138</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Tensorflow  Keras\n",
       "0        88         149     80\n",
       "1       133          39    104\n",
       "2        48          75     99\n",
       "3       144          69     26\n",
       "4        21          56    138\n",
       "..      ...         ...    ...\n",
       "145      87         138     79\n",
       "146      53          12    107\n",
       "147      88          43     77\n",
       "148     111          96     43\n",
       "149     117         138      8\n",
       "\n",
       "[150 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = [150,3]),# 计算机科目的考试成绩\n",
    "            columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d04bd96c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       88\n",
       "1      133\n",
       "2       48\n",
       "3      144\n",
       "4       21\n",
       "      ... \n",
       "145     87\n",
       "146     53\n",
       "147     88\n",
       "148    111\n",
       "149    117\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'] # 获取单列，Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "110c3d1e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       88\n",
       "1      133\n",
       "2       48\n",
       "3      144\n",
       "4       21\n",
       "      ... \n",
       "145     87\n",
       "146     53\n",
       "147     88\n",
       "148    111\n",
       "149    117\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.Python # 获取单列，Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3f6d2961",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>88</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>133</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>48</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>144</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>21</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>87</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>53</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>88</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>111</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>117</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Keras\n",
       "0        88     80\n",
       "1       133    104\n",
       "2        48     99\n",
       "3       144     26\n",
       "4        21    138\n",
       "..      ...    ...\n",
       "145      87     79\n",
       "146      53    107\n",
       "147      88     77\n",
       "148     111     43\n",
       "149     117      8\n",
       "\n",
       "[150 rows x 2 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['Python','Keras']] # 获取多列，DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3ac10e72",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>144</td>\n",
       "      <td>69</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>21</td>\n",
       "      <td>56</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7</td>\n",
       "      <td>27</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>78</td>\n",
       "      <td>27</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>57</td>\n",
       "      <td>54</td>\n",
       "      <td>116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>82</td>\n",
       "      <td>99</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>142</td>\n",
       "      <td>61</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>110</td>\n",
       "      <td>67</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>48</td>\n",
       "      <td>69</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>23</td>\n",
       "      <td>71</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>127</td>\n",
       "      <td>115</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>55</td>\n",
       "      <td>28</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "3      144          69     26\n",
       "4       21          56    138\n",
       "5        7          27     48\n",
       "6       78          27     90\n",
       "7       57          54    116\n",
       "8       82          99     44\n",
       "9      142          61     85\n",
       "10     110          67     60\n",
       "11      48          69     81\n",
       "12      23          71     19\n",
       "13     127         115     34\n",
       "14      55          28    146"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[3:15] # 行切片"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49b1ab9f",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "### 第二节 标签选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "8aaadb53",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>101</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>60</td>\n",
       "      <td>3</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>81</td>\n",
       "      <td>11</td>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>101</td>\n",
       "      <td>128</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>94</td>\n",
       "      <td>143</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>133</td>\n",
       "      <td>3</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>59</td>\n",
       "      <td>20</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>107</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>132</td>\n",
       "      <td>99</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>14</td>\n",
       "      <td>105</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     101          70     29\n",
       "B      60           3     11\n",
       "C      81          11    113\n",
       "D     101         128     44\n",
       "E      94         143     74\n",
       "F     133           3    139\n",
       "G      59          20    104\n",
       "H      49         107     90\n",
       "I     132          99      4\n",
       "J      14         105    146"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "                  index = list('ABCDEFGHIJ'),# 行标签\n",
    "                  columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2636d2b6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>101</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>81</td>\n",
       "      <td>11</td>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>101</td>\n",
       "      <td>128</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>133</td>\n",
       "      <td>3</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     101          70     29\n",
       "C      81          11    113\n",
       "D     101         128     44\n",
       "F     133           3    139"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['A','C','D','F']] # 选取指定行标签数据。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "04d4d480",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>101</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>60</td>\n",
       "      <td>3</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>81</td>\n",
       "      <td>11</td>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>101</td>\n",
       "      <td>128</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>94</td>\n",
       "      <td>143</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>133</td>\n",
       "      <td>3</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>59</td>\n",
       "      <td>20</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>107</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>132</td>\n",
       "      <td>99</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>14</td>\n",
       "      <td>105</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     101          70     29\n",
       "B      60           3     11\n",
       "C      81          11    113\n",
       "D     101         128     44\n",
       "E      94         143     74\n",
       "F     133           3    139\n",
       "G      59          20    104\n",
       "H      49         107     90\n",
       "I     132          99      4\n",
       "J      14         105    146"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['A':'E',['Python','Keras']] # 根据行标签切片，选取指定列标签的数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b32279f0",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>29</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>11</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>113</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>44</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>74</td>\n",
       "      <td>143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>139</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>104</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>90</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>146</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Keras  Tensorflow\n",
       "A     29          70\n",
       "B     11           3\n",
       "C    113          11\n",
       "D     44         128\n",
       "E     74         143\n",
       "F    139           3\n",
       "G    104          20\n",
       "H     90         107\n",
       "I      4          99\n",
       "J    146         105"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v0 = df.loc[:,['Keras','Tensorflow']] # :默认保留所有行\n",
    "v0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "76eb29bd",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>94</td>\n",
       "      <td>143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>59</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>132</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow\n",
       "E      94         143\n",
       "G      59          20\n",
       "I     132          99"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ss = df.loc['E'::2,'Python':'Tensorflow'] # 行切片从标签E开始每2个中取一个，列标签进行切片\n",
    "ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d2104c09",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "101"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = df.loc['A','Python'] # 选取标量值\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0e943eb",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "### 第三节 位置选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "24c39621",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>126</td>\n",
       "      <td>6</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>35</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>115</td>\n",
       "      <td>85</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>71</td>\n",
       "      <td>58</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>33</td>\n",
       "      <td>124</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>108</td>\n",
       "      <td>100</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>63</td>\n",
       "      <td>29</td>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>58</td>\n",
       "      <td>27</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     126           6     70\n",
       "B      35          53     61\n",
       "C      75          98     30\n",
       "D     115          85     80\n",
       "E      14           1    124\n",
       "F      71          58     63\n",
       "G      33         124     90\n",
       "H     108         100     28\n",
       "I      63          29    108\n",
       "J      58          27     54"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "index = list('ABCDEFGHIJ'),# 行标签\n",
    "columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "9b94bc24",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python         14\n",
       "Tensorflow      1\n",
       "Keras         124\n",
       "Name: E, dtype: int32"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[4] # 用整数位置选择。\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "8dfd61a8",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>115</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>71</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>33</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>108</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow\n",
       "C      75          98\n",
       "D     115          85\n",
       "E      14           1\n",
       "F      71          58\n",
       "G      33         124\n",
       "H     108         100"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[2:8,0:2] # 用整数切片，类似NumPy\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "1fbfb880",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>35</td>\n",
       "      <td>61</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>115</td>\n",
       "      <td>80</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>71</td>\n",
       "      <td>63</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Tensorflow\n",
       "B      35     61          53\n",
       "D     115     80          85\n",
       "F      71     63          58"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[[1,3,5],[0,2,1]] # 整数列表按位置切片\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "0cad0b9c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>35</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "B      35          53     61\n",
       "C      75          98     30"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[1:3,:] # 行切片\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7c957fbe",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>126</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>35</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>115</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>71</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>33</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>108</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>63</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>58</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow\n",
       "A     126           6\n",
       "B      35          53\n",
       "C      75          98\n",
       "D     115          85\n",
       "E      14           1\n",
       "F      71          58\n",
       "G      33         124\n",
       "H     108         100\n",
       "I      63          29\n",
       "J      58          27"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[:,:2] # 列切片\n",
    "aa\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9bd8dcc6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "70"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[0,2] # 选取标量值\n",
    "aa"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30ef0f88",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "### 第四节 boolean索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "1dcf929f",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>139</td>\n",
       "      <td>61</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>124</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>105</td>\n",
       "      <td>50</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>114</td>\n",
       "      <td>119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>133</td>\n",
       "      <td>85</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>91</td>\n",
       "      <td>33</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>105</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>26</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>85</td>\n",
       "      <td>52</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>25</td>\n",
       "      <td>89</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     139          61      8\n",
       "B     124          77     76\n",
       "C     105          50     42\n",
       "D      64         114    119\n",
       "E     133          85    105\n",
       "F      91          33     19\n",
       "G      87         105    133\n",
       "H     111          26     61\n",
       "I      85          52     73\n",
       "J      25          89    102"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "                index = list('ABCDEFGHIJ'),# 行标签，用户\n",
    "                columns=['Python','Tensorflow','Keras']) # 考试科目\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "44f54afc",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B     True\n",
       "C     True\n",
       "D    False\n",
       "E     True\n",
       "F    False\n",
       "G    False\n",
       "H     True\n",
       "I    False\n",
       "J    False\n",
       "Name: Python, dtype: bool"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond1 = df.Python > 100 # 判断Python分数是否大于100，返回值是boolean类型的Series\n",
    "cond1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "890707eb",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>139</td>\n",
       "      <td>61</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>124</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>105</td>\n",
       "      <td>50</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>133</td>\n",
       "      <td>85</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>26</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     139          61      8\n",
       "B     124          77     76\n",
       "C     105          50     42\n",
       "E     133          85    105\n",
       "H     111          26     61"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond1 = df[cond1] # 返回Python分数大于100分的用户所有考试科目数据\n",
    "cond1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f8ef354d",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>124</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64</td>\n",
       "      <td>114</td>\n",
       "      <td>119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>133</td>\n",
       "      <td>85</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>105</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>26</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>85</td>\n",
       "      <td>52</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "B     124          77     76\n",
       "D      64         114    119\n",
       "E     133          85    105\n",
       "G      87         105    133\n",
       "H     111          26     61\n",
       "I      85          52     73"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond2 = (df.Python > 50) & (df['Keras'] > 50) # &与运算\n",
    "df[cond2] # 返回Python和Keras同时大于50分的用户的所有考试科目数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "c5560534",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>139.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>124.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>76.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>105.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>64.0</td>\n",
       "      <td>114.0</td>\n",
       "      <td>119.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>133.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>105.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>91.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>133.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>85.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>NaN</td>\n",
       "      <td>89.0</td>\n",
       "      <td>102.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A   139.0        61.0    NaN\n",
       "B   124.0        77.0   76.0\n",
       "C   105.0         NaN    NaN\n",
       "D    64.0       114.0  119.0\n",
       "E   133.0        85.0  105.0\n",
       "F    91.0         NaN    NaN\n",
       "G    87.0       105.0  133.0\n",
       "H   111.0         NaN   61.0\n",
       "I    85.0        52.0   73.0\n",
       "J     NaN        89.0  102.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df > 50]# 选择DataFrame中满足条件的值，如果满足返回值，不然返回空数据NaN\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "fdae767d",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>139</td>\n",
       "      <td>61</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>105</td>\n",
       "      <td>50</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>91</td>\n",
       "      <td>33</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     139          61      8\n",
       "C     105          50     42\n",
       "F      91          33     19"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df[df.index.isin(['A','C','F'])] # isin判断是否在数组中，返回也是boolean类型值\n",
    "aa"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d01e18b9",
   "metadata": {
    "heading_collapsed": true,
    "hidden": true
   },
   "source": [
    "### 第五节 赋值操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "47706f3f",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>25</td>\n",
       "      <td>56</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>67</td>\n",
       "      <td>49</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>83</td>\n",
       "      <td>84</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>74</td>\n",
       "      <td>140</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>84</td>\n",
       "      <td>148</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>105</td>\n",
       "      <td>12</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>8</td>\n",
       "      <td>112</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>51</td>\n",
       "      <td>54</td>\n",
       "      <td>111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>83</td>\n",
       "      <td>17</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>95</td>\n",
       "      <td>71</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      25          56     33\n",
       "B      67          49    117\n",
       "C      83          84    104\n",
       "D      74         140    139\n",
       "E      84         148     36\n",
       "F     105          12    141\n",
       "G       8         112    140\n",
       "H      51          54    111\n",
       "I      83          17     52\n",
       "J      95          71    131"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "        index = list('ABCDEFGHIJ'),# 行标签，用户\n",
    "        columns=['Python','Tensorflow','Keras']) # 考试科目\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "246b8db6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "B     15\n",
       "C      0\n",
       "D      6\n",
       "E    128\n",
       "F     72\n",
       "G     38\n",
       "H     50\n",
       "I     71\n",
       "J    138\n",
       "Name: PyTorch, dtype: int32"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(data = np.random.randint(0,150,size =9),index=list('BCDEFGHIJ'),name = 'PyTorch')\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "02051801",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "B     15\n",
       "C      0\n",
       "D      6\n",
       "E    128\n",
       "F     72\n",
       "G     38\n",
       "H     50\n",
       "I     71\n",
       "J    138\n",
       "Name: PyTorch, dtype: int32"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df['PyTorch'] = s # 增加一列，DataFrame行索引自动对齐\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "52bd5aec",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "256"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.loc['A','Python'] = 256 # 按标签赋值\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a4ec1c62",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "512"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.iloc[3,2] = 512 # 按位置赋值\n",
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "a40e2a67",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>PyTorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>56</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>128</td>\n",
       "      <td>49</td>\n",
       "      <td>117</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>128</td>\n",
       "      <td>84</td>\n",
       "      <td>104</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>128</td>\n",
       "      <td>140</td>\n",
       "      <td>512</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>128</td>\n",
       "      <td>148</td>\n",
       "      <td>36</td>\n",
       "      <td>128.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>128</td>\n",
       "      <td>12</td>\n",
       "      <td>141</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>128</td>\n",
       "      <td>112</td>\n",
       "      <td>140</td>\n",
       "      <td>38.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>128</td>\n",
       "      <td>54</td>\n",
       "      <td>111</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>128</td>\n",
       "      <td>17</td>\n",
       "      <td>52</td>\n",
       "      <td>71.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>128</td>\n",
       "      <td>71</td>\n",
       "      <td>131</td>\n",
       "      <td>138.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras  PyTorch\n",
       "A     128          56     33      NaN\n",
       "B     128          49    117     15.0\n",
       "C     128          84    104      0.0\n",
       "D     128         140    512      6.0\n",
       "E     128         148     36    128.0\n",
       "F     128          12    141     72.0\n",
       "G     128         112    140     38.0\n",
       "H     128          54    111     50.0\n",
       "I     128          17     52     71.0\n",
       "J     128          71    131    138.0"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = df.loc[:,'Python'] = np.array([128]*10) # 按NumPy数组进行赋值\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "70edc169",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>PyTorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>-128</td>\n",
       "      <td>56</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-128</td>\n",
       "      <td>49</td>\n",
       "      <td>117</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-128</td>\n",
       "      <td>84</td>\n",
       "      <td>104</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-128</td>\n",
       "      <td>-140</td>\n",
       "      <td>-512</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-128</td>\n",
       "      <td>-148</td>\n",
       "      <td>36</td>\n",
       "      <td>-128.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-128</td>\n",
       "      <td>12</td>\n",
       "      <td>-141</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>-128</td>\n",
       "      <td>112</td>\n",
       "      <td>-140</td>\n",
       "      <td>38.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-128</td>\n",
       "      <td>54</td>\n",
       "      <td>111</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-128</td>\n",
       "      <td>17</td>\n",
       "      <td>52</td>\n",
       "      <td>71.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-128</td>\n",
       "      <td>71</td>\n",
       "      <td>-131</td>\n",
       "      <td>-138.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras  PyTorch\n",
       "A    -128          56     33      NaN\n",
       "B    -128          49    117     15.0\n",
       "C    -128          84    104      0.0\n",
       "D    -128        -140   -512      6.0\n",
       "E    -128        -148     36   -128.0\n",
       "F    -128          12   -141     72.0\n",
       "G    -128         112   -140     38.0\n",
       "H    -128          54    111     50.0\n",
       "I    -128          17     52     71.0\n",
       "J    -128          71   -131   -138.0"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df >= 128] = -df # 按照where条件进行赋值，大于等于128变成原来的负数，否则不变\n",
    "df\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98326e6c",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 第六部分 数据集成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79886d61",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 第一节 concat数据串联"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "32f946ed",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>57</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>5</td>\n",
       "      <td>120</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>31</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>86</td>\n",
       "      <td>11</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>63</td>\n",
       "      <td>37</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>38</td>\n",
       "      <td>95</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>17</td>\n",
       "      <td>12</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>136</td>\n",
       "      <td>30</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>30</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>7</td>\n",
       "      <td>137</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     128          57     78\n",
       "B       5         120     55\n",
       "C       4          31     64\n",
       "D      86          11     42\n",
       "E      63          37     58\n",
       "F      38          95      4\n",
       "G      17          12     38\n",
       "H     136          30     97\n",
       "I      30          22     79\n",
       "J       7         137     86"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "            index = list('ABCDEFGHIJ'),# 行标签，用户\n",
    "            columns=['Python','Tensorflow','Keras']) # 考试科目\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "ffaee381",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>72</td>\n",
       "      <td>117</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>27</td>\n",
       "      <td>102</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>36</td>\n",
       "      <td>119</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>129</td>\n",
       "      <td>94</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>65</td>\n",
       "      <td>35</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>21</td>\n",
       "      <td>16</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>144</td>\n",
       "      <td>0</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>41</td>\n",
       "      <td>113</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>91</td>\n",
       "      <td>91</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>93</td>\n",
       "      <td>12</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "K      72         117     45\n",
       "L      27         102     91\n",
       "M      36         119     71\n",
       "N     129          94     96\n",
       "O      65          35     65\n",
       "P      21          16    142\n",
       "Q     144           0     71\n",
       "R      41         113     84\n",
       "S      91          91     43\n",
       "T      93          12      8"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.DataFrame(data = np.random.randint(0,150,size = [10,3]),# 计算机科目的考试成绩\n",
    "        index = list('KLMNOPQRST'),# 行标签，用户\n",
    "        columns=['Python','Tensorflow','Keras']) # 考试科目\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "4b851532",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PyTorch</th>\n",
       "      <th>Paddle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>25</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>21</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>123</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>111</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>61</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>30</td>\n",
       "      <td>116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>121</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>63</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>104</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>101</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PyTorch  Paddle\n",
       "A       25     105\n",
       "B       21      48\n",
       "C      123      82\n",
       "D      111     140\n",
       "E       61       6\n",
       "F       30     116\n",
       "G      121      85\n",
       "H       63      72\n",
       "I      104      24\n",
       "J      101      65"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = pd.DataFrame(data = np.random.randint(0,150,size = (10,2)),\n",
    "index = list('ABCDEFGHIJ'),\n",
    "columns=['PyTorch','Paddle'])\n",
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "4feefff2",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>57</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>5</td>\n",
       "      <td>120</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>31</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>86</td>\n",
       "      <td>11</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>63</td>\n",
       "      <td>37</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>38</td>\n",
       "      <td>95</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>17</td>\n",
       "      <td>12</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>136</td>\n",
       "      <td>30</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>30</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>7</td>\n",
       "      <td>137</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>72</td>\n",
       "      <td>117</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>27</td>\n",
       "      <td>102</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>36</td>\n",
       "      <td>119</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>129</td>\n",
       "      <td>94</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>65</td>\n",
       "      <td>35</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>21</td>\n",
       "      <td>16</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>144</td>\n",
       "      <td>0</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>41</td>\n",
       "      <td>113</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>91</td>\n",
       "      <td>91</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>93</td>\n",
       "      <td>12</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     128          57     78\n",
       "B       5         120     55\n",
       "C       4          31     64\n",
       "D      86          11     42\n",
       "E      63          37     58\n",
       "F      38          95      4\n",
       "G      17          12     38\n",
       "H     136          30     97\n",
       "I      30          22     79\n",
       "J       7         137     86\n",
       "K      72         117     45\n",
       "L      27         102     91\n",
       "M      36         119     71\n",
       "N     129          94     96\n",
       "O      65          35     65\n",
       "P      21          16    142\n",
       "Q     144           0     71\n",
       "R      41         113     84\n",
       "S      91          91     43\n",
       "T      93          12      8"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],axis = 0) # df1和df2行串联，df2的行追加df2行后面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "c41dd2cb",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>57</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>5</td>\n",
       "      <td>120</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>31</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>86</td>\n",
       "      <td>11</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>63</td>\n",
       "      <td>37</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>38</td>\n",
       "      <td>95</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>17</td>\n",
       "      <td>12</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>136</td>\n",
       "      <td>30</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>30</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>7</td>\n",
       "      <td>137</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>72</td>\n",
       "      <td>117</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>27</td>\n",
       "      <td>102</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>36</td>\n",
       "      <td>119</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>129</td>\n",
       "      <td>94</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>65</td>\n",
       "      <td>35</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>21</td>\n",
       "      <td>16</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>144</td>\n",
       "      <td>0</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>41</td>\n",
       "      <td>113</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>91</td>\n",
       "      <td>91</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>93</td>\n",
       "      <td>12</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     128          57     78\n",
       "B       5         120     55\n",
       "C       4          31     64\n",
       "D      86          11     42\n",
       "E      63          37     58\n",
       "F      38          95      4\n",
       "G      17          12     38\n",
       "H     136          30     97\n",
       "I      30          22     79\n",
       "J       7         137     86\n",
       "K      72         117     45\n",
       "L      27         102     91\n",
       "M      36         119     71\n",
       "N     129          94     96\n",
       "O      65          35     65\n",
       "P      21          16    142\n",
       "Q     144           0     71\n",
       "R      41         113     84\n",
       "S      91          91     43\n",
       "T      93          12      8"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2) # 在df1后面追加df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "1ad4f5b7",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>PyTorch</th>\n",
       "      <th>Paddle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>57</td>\n",
       "      <td>78</td>\n",
       "      <td>25</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>5</td>\n",
       "      <td>120</td>\n",
       "      <td>55</td>\n",
       "      <td>21</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>31</td>\n",
       "      <td>64</td>\n",
       "      <td>123</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>86</td>\n",
       "      <td>11</td>\n",
       "      <td>42</td>\n",
       "      <td>111</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>63</td>\n",
       "      <td>37</td>\n",
       "      <td>58</td>\n",
       "      <td>61</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>38</td>\n",
       "      <td>95</td>\n",
       "      <td>4</td>\n",
       "      <td>30</td>\n",
       "      <td>116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>17</td>\n",
       "      <td>12</td>\n",
       "      <td>38</td>\n",
       "      <td>121</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>136</td>\n",
       "      <td>30</td>\n",
       "      <td>97</td>\n",
       "      <td>63</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>30</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "      <td>104</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>7</td>\n",
       "      <td>137</td>\n",
       "      <td>86</td>\n",
       "      <td>101</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras  PyTorch  Paddle\n",
       "A     128          57     78       25     105\n",
       "B       5         120     55       21      48\n",
       "C       4          31     64      123      82\n",
       "D      86          11     42      111     140\n",
       "E      63          37     58       61       6\n",
       "F      38          95      4       30     116\n",
       "G      17          12     38      121      85\n",
       "H     136          30     97       63      72\n",
       "I      30          22     79      104      24\n",
       "J       7         137     86      101      65"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df3],axis = 1) # df1和df2列串联，df2的列追加到df1列后面\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e187ab4c",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 第二节 插入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6b8b7391",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>123</td>\n",
       "      <td>27</td>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>127</td>\n",
       "      <td>10</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>95</td>\n",
       "      <td>45</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>20</td>\n",
       "      <td>67</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>64</td>\n",
       "      <td>109</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>137</td>\n",
       "      <td>58</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>119</td>\n",
       "      <td>110</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>105</td>\n",
       "      <td>121</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>120</td>\n",
       "      <td>50</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>62</td>\n",
       "      <td>85</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Tensorflow\n",
       "A     123     27         148\n",
       "B     127     10         104\n",
       "C      95     45          42\n",
       "D      20     67          40\n",
       "E      64    109          82\n",
       "F     137     58          10\n",
       "G     119    110          99\n",
       "H     105    121         101\n",
       "I     120     50          30\n",
       "J      62     85          37"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,151,size = (10,3)),\n",
    "        index = list('ABCDEFGHIJ'),\n",
    "        columns = ['Python','Keras','Tensorflow'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9f0fdbf6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Pytorch</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>123</td>\n",
       "      <td>1024</td>\n",
       "      <td>27</td>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>127</td>\n",
       "      <td>1024</td>\n",
       "      <td>10</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>95</td>\n",
       "      <td>1024</td>\n",
       "      <td>45</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>20</td>\n",
       "      <td>1024</td>\n",
       "      <td>67</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>64</td>\n",
       "      <td>1024</td>\n",
       "      <td>109</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>137</td>\n",
       "      <td>1024</td>\n",
       "      <td>58</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>119</td>\n",
       "      <td>1024</td>\n",
       "      <td>110</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>105</td>\n",
       "      <td>1024</td>\n",
       "      <td>121</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>120</td>\n",
       "      <td>1024</td>\n",
       "      <td>50</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>62</td>\n",
       "      <td>1024</td>\n",
       "      <td>85</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Pytorch  Keras  Tensorflow\n",
       "A     123     1024     27         148\n",
       "B     127     1024     10         104\n",
       "C      95     1024     45          42\n",
       "D      20     1024     67          40\n",
       "E      64     1024    109          82\n",
       "F     137     1024     58          10\n",
       "G     119     1024    110          99\n",
       "H     105     1024    121         101\n",
       "I     120     1024     50          30\n",
       "J      62     1024     85          37"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.insert(loc = 1,column='Pytorch',value=1024) # 插入列\n",
    "df\n",
    "# 对行的操作，使用追加append，默认在最后面，无法指定位置\n",
    "# 如果想要在指定位置插入行：切割-添加-合并"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aabed993",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 第三节 Join SQL风格合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dd84872c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ella</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight\n",
       "0   softpo      70\n",
       "1   Daniel      55\n",
       "2  Brandon      75\n",
       "3     Ella      65"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.DataFrame(data = {'name':['softpo','Daniel','Brandon','Ella'],'weight':[70,55,75,65]})\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "258094dd",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Cindy</td>\n",
       "      <td>166</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  height\n",
       "0   softpo     172\n",
       "1   Daniel     170\n",
       "2  Brandon     170\n",
       "3    Cindy     166"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 表二中记录的是name和身高信息\n",
    "df2 = pd.DataFrame(data = {'name':['softpo','Daniel','Brandon','Cindy'],'height':[172,170,170,166]})\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ce9e151e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名字</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Cindy</td>\n",
       "      <td>166</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        名字  height\n",
       "0   softpo     172\n",
       "1   Daniel     170\n",
       "2  Brandon     170\n",
       "3    Cindy     166"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = pd.DataFrame(data = {'名字':['softpo','Daniel','Brandon','Cindy'],'height':[172,170,170,166]})\n",
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6e32cfda",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight  height\n",
       "0   softpo      70     172\n",
       "1   Daniel      55     170\n",
       "2  Brandon      75     170"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据共同的name将俩表的数据，进行合并\n",
    "pd.merge(df1,df2,how = 'inner',# 内合并代表两对象交集\n",
    "         on = 'name')\n",
    "         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cf48719e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>名字</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70.0</td>\n",
       "      <td>softpo</td>\n",
       "      <td>172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55.0</td>\n",
       "      <td>Daniel</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75.0</td>\n",
       "      <td>Brandon</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ella</td>\n",
       "      <td>65.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Cindy</td>\n",
       "      <td>166.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight       名字  height\n",
       "0   softpo    70.0   softpo   172.0\n",
       "1   Daniel    55.0   Daniel   170.0\n",
       "2  Brandon    75.0  Brandon   170.0\n",
       "3     Ella    65.0      NaN     NaN\n",
       "4      NaN     NaN    Cindy   166.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df1,df3,\n",
    "        how = 'outer',# 全外连接，两对象并集\n",
    "        left_on = 'name',# 左边DataFrame使用列标签 name进行合并\n",
    "        right_on = '名字')# 右边DataFrame使用列标签 名字进行合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5eadf46f",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>96</td>\n",
       "      <td>96</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>31</td>\n",
       "      <td>75</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>12</td>\n",
       "      <td>136</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>45</td>\n",
       "      <td>49</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>139</td>\n",
       "      <td>26</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>44</td>\n",
       "      <td>88</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>72</td>\n",
       "      <td>47</td>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>0</td>\n",
       "      <td>66</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>65</td>\n",
       "      <td>101</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>81</td>\n",
       "      <td>86</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Tensorflow\n",
       "A      96     96         115\n",
       "B      31     75          29\n",
       "C      12    136         107\n",
       "D      45     49         121\n",
       "E     139     26          72\n",
       "F      44     88           9\n",
       "H      72     47         108\n",
       "I       0     66         114\n",
       "J      65    101          25\n",
       "K      81     86         141"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建10名学生的考试成绩\n",
    "df4 = pd.DataFrame(data = np.random.randint(0,151,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Keras','Tensorflow'])\n",
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "66cea587",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>102.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>85.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>71.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>75.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>63.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>102.7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     平均分\n",
       "A  102.3\n",
       "B   45.0\n",
       "C   85.0\n",
       "D   71.7\n",
       "E   79.0\n",
       "F   47.0\n",
       "H   75.7\n",
       "I   60.0\n",
       "J   63.7\n",
       "K  102.7"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每位学生各科平均分，转换成DataFrame\n",
    "score_mean = pd.DataFrame(df4.mean(axis = 1).round(1),columns=['平均分'])\n",
    "score_mean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5bb340d7",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>96</td>\n",
       "      <td>96</td>\n",
       "      <td>115</td>\n",
       "      <td>102.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>31</td>\n",
       "      <td>75</td>\n",
       "      <td>29</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>12</td>\n",
       "      <td>136</td>\n",
       "      <td>107</td>\n",
       "      <td>85.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>45</td>\n",
       "      <td>49</td>\n",
       "      <td>121</td>\n",
       "      <td>71.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>139</td>\n",
       "      <td>26</td>\n",
       "      <td>72</td>\n",
       "      <td>79.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>44</td>\n",
       "      <td>88</td>\n",
       "      <td>9</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>72</td>\n",
       "      <td>47</td>\n",
       "      <td>108</td>\n",
       "      <td>75.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>0</td>\n",
       "      <td>66</td>\n",
       "      <td>114</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>65</td>\n",
       "      <td>101</td>\n",
       "      <td>25</td>\n",
       "      <td>63.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>81</td>\n",
       "      <td>86</td>\n",
       "      <td>141</td>\n",
       "      <td>102.7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Tensorflow    平均分\n",
       "A      96     96         115  102.3\n",
       "B      31     75          29   45.0\n",
       "C      12    136         107   85.0\n",
       "D      45     49         121   71.7\n",
       "E     139     26          72   79.0\n",
       "F      44     88           9   47.0\n",
       "H      72     47         108   75.7\n",
       "I       0     66         114   60.0\n",
       "J      65    101          25   63.7\n",
       "K      81     86         141  102.7"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将平均分和df3使用merge进行合并，它俩有共同的行索引\n",
    "pd.merge(left = df4,right = score_mean,\n",
    "        left_index=True,# 左边DataFrame使用行索引进行合并\n",
    "        right_index=True)# 右边的DataFrame使用行索引进行合并\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa13a22d",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 第七部分 数据清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c202e409",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0    red   10.0\n",
       "1   blue   20.0\n",
       "2    red   10.0\n",
       "3  green   15.0\n",
       "4   blue   20.0\n",
       "5   None    0.0\n",
       "6    red    NaN"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = {'color':['red','blue','red','green','blue',None,'red'],\n",
    "            'price':[10,20,10,15,20,0,np.NaN]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3e77f4d4",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0    red   10.0\n",
       "1   blue   20.0\n",
       "3  green   15.0\n",
       "5   None    0.0\n",
       "6    red    NaN"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、重复数据过滤\n",
    "bool = df.duplicated() # 判断是否存在重复数据\n",
    "bool\n",
    "df.drop_duplicates() # 删除重复数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e697de9c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1111</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>1111.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color   price\n",
       "0    red    10.0\n",
       "1   blue    20.0\n",
       "2    red    10.0\n",
       "3  green    15.0\n",
       "4   blue    20.0\n",
       "5   1111     0.0\n",
       "6    red  1111.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、空数据过滤\n",
    "df.isnull() # 判断是否存在空数据，存在返回True，否则返回False\n",
    "df.dropna(how = 'any') # 删除空数据\n",
    "df.fillna(value=1111) # 填充空数据\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "08f47dd4",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price\n",
       "0   10.0\n",
       "1   20.0\n",
       "2   10.0\n",
       "3   15.0\n",
       "4   20.0\n",
       "5    0.0\n",
       "6    NaN"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、指定行或者列过滤\n",
    "del df['color'] # 直接删除某列\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "006a3d40",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price\n",
       "0   10.0\n",
       "1   20.0\n",
       "2   10.0\n",
       "3   15.0\n",
       "4   20.0\n",
       "5    0.0\n",
       "6    NaN"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(labels = ['price'],axis = 1)# 删除指定列\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "9fbf98b1",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price\n",
       "0   10.0\n",
       "1   20.0\n",
       "2   10.0\n",
       "3   15.0\n",
       "4   20.0\n",
       "5    0.0\n",
       "6    NaN"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(labels = [0,1,5],axis = 0) # 删除指定行\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3fee6366",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>France</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>256</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  France\n",
       "dog      3       1\n",
       "cat      2     256"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4、函数filter使用\n",
    "df = pd.DataFrame(np.array(([3,7,1], [2, 8, 256])),\n",
    "        index=['dog', 'cat'],\n",
    "        columns=['China', 'America', 'France'])\n",
    "df.filter(items=['China', 'France'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ec88bc6a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America\n",
       "dog      3        7\n",
       "cat      2        8"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据正则表达式删选列标签\n",
    "df.filter(regex='a$', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c2628264",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "      <th>France</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America  France\n",
       "dog      3        7       1"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择行中包含og\n",
    "df.filter(like='og', axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6f90d809",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.885519</td>\n",
       "      <td>-0.055474</td>\n",
       "      <td>-0.485137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.194417</td>\n",
       "      <td>-1.000526</td>\n",
       "      <td>0.007548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.634233</td>\n",
       "      <td>-1.201644</td>\n",
       "      <td>-0.915398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.189382</td>\n",
       "      <td>-1.421360</td>\n",
       "      <td>-0.381546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.001202</td>\n",
       "      <td>0.002457</td>\n",
       "      <td>0.237300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>0.519291</td>\n",
       "      <td>0.902766</td>\n",
       "      <td>1.189161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>1.130394</td>\n",
       "      <td>1.759401</td>\n",
       "      <td>0.615808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>0.540290</td>\n",
       "      <td>1.527262</td>\n",
       "      <td>1.086977</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>0.597985</td>\n",
       "      <td>0.346845</td>\n",
       "      <td>-0.281093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>-0.233147</td>\n",
       "      <td>-0.773361</td>\n",
       "      <td>0.129293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10000 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             0         1         2\n",
       "0    -0.885519 -0.055474 -0.485137\n",
       "1    -1.194417 -1.000526  0.007548\n",
       "2    -1.634233 -1.201644 -0.915398\n",
       "3    -0.189382 -1.421360 -0.381546\n",
       "4    -0.001202  0.002457  0.237300\n",
       "...        ...       ...       ...\n",
       "9995  0.519291  0.902766  1.189161\n",
       "9996  1.130394  1.759401  0.615808\n",
       "9997  0.540290  1.527262  1.086977\n",
       "9998  0.597985  0.346845 -0.281093\n",
       "9999 -0.233147 -0.773361  0.129293\n",
       "\n",
       "[10000 rows x 3 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5、异常值过滤\n",
    "df2 = pd.DataFrame(data = np.random.randn(10000,3)) # 正态分布数据\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2fe3a634",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       False\n",
       "1       False\n",
       "2       False\n",
       "3       False\n",
       "4       False\n",
       "        ...  \n",
       "9995    False\n",
       "9996    False\n",
       "9997    False\n",
       "9998    False\n",
       "9999    False\n",
       "Length: 10000, dtype: bool"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3σ过滤异常值，σ即是标准差\n",
    "cond = (df2 > 3*df2.std()).any(axis = 1)\n",
    "cond"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "e836ad57",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([ 355,  627, 1811, 1846, 1907, 2018, 2823, 3802, 3874, 3925, 3950,\n",
       "            4005, 4149, 4165, 4241, 4252, 4315, 4618, 4809, 4904, 5572, 5672,\n",
       "            5949, 6319, 6320, 6367, 6476, 6667, 6696, 6922, 7158, 7390, 7664,\n",
       "            7705, 7735, 8186, 8377, 8759, 9027, 9108, 9139, 9245],\n",
       "           dtype='int64')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = df2[cond].index # 不满足条件的行索引\n",
    "index\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "2e7d8954",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.885519</td>\n",
       "      <td>-0.055474</td>\n",
       "      <td>-0.485137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.194417</td>\n",
       "      <td>-1.000526</td>\n",
       "      <td>0.007548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.634233</td>\n",
       "      <td>-1.201644</td>\n",
       "      <td>-0.915398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.189382</td>\n",
       "      <td>-1.421360</td>\n",
       "      <td>-0.381546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.001202</td>\n",
       "      <td>0.002457</td>\n",
       "      <td>0.237300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>0.519291</td>\n",
       "      <td>0.902766</td>\n",
       "      <td>1.189161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>1.130394</td>\n",
       "      <td>1.759401</td>\n",
       "      <td>0.615808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>0.540290</td>\n",
       "      <td>1.527262</td>\n",
       "      <td>1.086977</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>0.597985</td>\n",
       "      <td>0.346845</td>\n",
       "      <td>-0.281093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>-0.233147</td>\n",
       "      <td>-0.773361</td>\n",
       "      <td>0.129293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9958 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             0         1         2\n",
       "0    -0.885519 -0.055474 -0.485137\n",
       "1    -1.194417 -1.000526  0.007548\n",
       "2    -1.634233 -1.201644 -0.915398\n",
       "3    -0.189382 -1.421360 -0.381546\n",
       "4    -0.001202  0.002457  0.237300\n",
       "...        ...       ...       ...\n",
       "9995  0.519291  0.902766  1.189161\n",
       "9996  1.130394  1.759401  0.615808\n",
       "9997  0.540290  1.527262  1.086977\n",
       "9998  0.597985  0.346845 -0.281093\n",
       "9999 -0.233147 -0.773361  0.129293\n",
       "\n",
       "[9958 rows x 3 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.drop(labels=index,axis = 0) # 根据行索引，进行数据删除"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce4137cb",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数据转换"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "951d3560",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas轴和元素转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "7c138784",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       0           0    2.0\n",
       "B       5           3    6.0\n",
       "C       4           1    8.0\n",
       "D       3           7    5.0\n",
       "E       5           3    NaN\n",
       "F       2           1    2.0\n",
       "H       4           7    8.0\n",
       "I       7           4    1.0\n",
       "J       1           6    7.0\n",
       "K       3           9    4.0"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df.iloc[4,2] = None # 空数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "a987384c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人工智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    人工智能  Tensorflow  Keras\n",
       "AA     0           0    2.0\n",
       "BB     5           3    6.0\n",
       "C      4           1    8.0\n",
       "D      3           7    5.0\n",
       "E      5           3    NaN\n",
       "F      2           1    2.0\n",
       "H      4           7    8.0\n",
       "I      7           4    1.0\n",
       "J      1           6    7.0\n",
       "K      3           9    4.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1、重命名轴索引\n",
    "df = df.rename(index = {'A':'AA','B':'BB'},columns = {'Python':'人工智能'})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "b83a6a7e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人工智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1024</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1024</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    人工智能  Tensorflow  Keras\n",
       "AA     0           0    2.0\n",
       "BB     5        1024    6.0\n",
       "C      4           1    8.0\n",
       "D   1024           7    5.0\n",
       "E      5        1024    NaN\n",
       "F      2           1    2.0\n",
       "H      4           7    8.0\n",
       "I      7           4    1.0\n",
       "J      1           6    7.0\n",
       "K   1024           9    4.0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、替换值\n",
    "df = df.replace(3,1024) #将3替换为1024\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "cc2d79e8",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人工智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>2048</td>\n",
       "      <td>2048</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1024</td>\n",
       "      <td>2048</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>2048</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2048</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>2048.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1024</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    人工智能  Tensorflow   Keras\n",
       "AA  2048        2048     2.0\n",
       "BB     5        1024     6.0\n",
       "C      4           1     8.0\n",
       "D   1024        2048     5.0\n",
       "E      5        1024     NaN\n",
       "F      2           1     2.0\n",
       "H      4        2048     8.0\n",
       "I   2048           4     1.0\n",
       "J      1           6  2048.0\n",
       "K   1024           9     4.0"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.replace([0,7],2048) # 将0和7替换为2048\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "ef06e3a8",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人工智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>2048</td>\n",
       "      <td>2048</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1024</td>\n",
       "      <td>2048</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>998.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>2048</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2048</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>2048.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1024</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    人工智能  Tensorflow   Keras\n",
       "AA  2048        2048     2.0\n",
       "BB     5        1024     6.0\n",
       "C      4           1     8.0\n",
       "D   1024        2048     5.0\n",
       "E      5        1024   998.0\n",
       "F      2           1     2.0\n",
       "H      4        2048     8.0\n",
       "I   2048           4     1.0\n",
       "J      1           6  2048.0\n",
       "K   1024           9     4.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.replace({0:512,np.nan:998}) # 根据字典键值对进行替换\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "50972ff9",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人工智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>2048</td>\n",
       "      <td>2048</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1024</td>\n",
       "      <td>2048</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>1024</td>\n",
       "      <td>998.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-1024</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>4</td>\n",
       "      <td>2048</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2048</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>2048.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1024</td>\n",
       "      <td>9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    人工智能  Tensorflow   Keras\n",
       "AA  2048        2048     2.0\n",
       "BB     5        1024     6.0\n",
       "C      4           1     8.0\n",
       "D   1024        2048     5.0\n",
       "E      5        1024   998.0\n",
       "F  -1024           1     2.0\n",
       "H      4        2048     8.0\n",
       "I   2048           4     1.0\n",
       "J      1           6  2048.0\n",
       "K   1024           9     4.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.replace({'人工智能':2},-1024) # 将Python这一列中等于2的，替换为-1024\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fef3c87c",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## map Series元素改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "f1a24bba",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       4           9      0\n",
       "B       7           3      1\n",
       "C       3           0      5\n",
       "D       2           8      6\n",
       "E       0           7      0\n",
       "F       5           2      7\n",
       "H       2           0      6\n",
       "I       7           4      0\n",
       "J       8           9      0\n",
       "K       7           9      9"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "e8f67a5e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       4           9    0.0\n",
       "B       7           3    1.0\n",
       "C       3           0    5.0\n",
       "D       2           8    6.0\n",
       "E       0           7    NaN\n",
       "F       5           2    7.0\n",
       "H       2           0    6.0\n",
       "I       7           4    0.0\n",
       "J       8           9    0.0\n",
       "K       7           9    9.0"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[4,2] = None # 空数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "b2526b30",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A      NaN\n",
       "B    Hello\n",
       "C    World\n",
       "D      NaN\n",
       "E      NaN\n",
       "F       AI\n",
       "H      NaN\n",
       "I      NaN\n",
       "J      NaN\n",
       "K      NaN\n",
       "Name: Keras, dtype: object"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、map批量元素改变，Series专有\n",
    "df = df['Keras'].map({1:'Hello',5:'World',7:'AI'}) # 字典映射\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "ed1002ca",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       4           4      7\n",
       "B       4           2      5\n",
       "C       2           1      6\n",
       "D       2           6      3\n",
       "E       1           4      0\n",
       "F       5           0      7\n",
       "H       0           9      9\n",
       "I       7           3      8\n",
       "J       6           5      3\n",
       "K       0           5      3"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "319dcb9c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    False\n",
       "B    False\n",
       "C    False\n",
       "D    False\n",
       "E    False\n",
       "F     True\n",
       "H    False\n",
       "I     True\n",
       "J     True\n",
       "K    False\n",
       "Name: Python, dtype: bool"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df['Python'].map(lambda x:True if x >=5 else False) # 隐式函数映射\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "d15e74ae",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       5           6      8\n",
       "B       4           7      2\n",
       "C       5           8      7\n",
       "D       3           2      7\n",
       "E       9           6      7\n",
       "F       1           9      2\n",
       "H       1           7      8\n",
       "I       6           0      5\n",
       "J       1           2      4\n",
       "K       8           7      3"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "1c60ed55",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B    False\n",
       "C     None\n",
       "D     None\n",
       "E     True\n",
       "F     True\n",
       "H    False\n",
       "I     True\n",
       "J     None\n",
       "K    False\n",
       "Name: Tensorflow, dtype: object"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def convert(x): # 显示函数映射\n",
    "    if x%3 == 0:\n",
    "        return True\n",
    "    elif x%3 == 1:\n",
    "        return False\n",
    "df['Tensorflow'].map(convert)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9a27640",
   "metadata": {
    "hidden": true
   },
   "source": [
    "##  apply元素改变。既支持 Series，也支持 DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "ac34cac7",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       2           3      7\n",
       "B       6           5      0\n",
       "C       8           0      7\n",
       "D       8           1      1\n",
       "E       6           1      4\n",
       "F       3           0      2\n",
       "H       3           8      9\n",
       "I       2           1      1\n",
       "J       6           6      5\n",
       "K       2           9      7"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "    index = list('ABCDEFHIJK'),\n",
    "    columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "6049a070",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       2           3    7.0\n",
       "B       6           5    0.0\n",
       "C       8           0    7.0\n",
       "D       8           1    1.0\n",
       "E       6           1    NaN\n",
       "F       3           0    2.0\n",
       "H       3           8    9.0\n",
       "I       2           1    1.0\n",
       "J       6           6    5.0\n",
       "K       2           9    7.0"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[4,2] = None # 空数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "9ddd7d90",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B    False\n",
       "C     True\n",
       "D    False\n",
       "E    False\n",
       "F    False\n",
       "H     True\n",
       "I    False\n",
       "J    False\n",
       "K     True\n",
       "Name: Keras, dtype: bool"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、apply 应用方法数据转换，通用\n",
    "# Series，其中x是Series中元素\n",
    "df = df['Keras'].apply(lambda x:True if x >5 else False)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "22f86487",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       1           5      4\n",
       "B       9           2      6\n",
       "C       5           0      8\n",
       "D       6           6      0\n",
       "E       9           7      0\n",
       "F       4           1      5\n",
       "H       6           8      5\n",
       "I       6           1      8\n",
       "J       4           8      3\n",
       "K       0           3      6"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "    index = list('ABCDEFHIJK'),\n",
    "    columns=['Python','Tensorflow','Keras'])\n",
    "df "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "d060d258",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        5.5\n",
       "Tensorflow    4.0\n",
       "Keras         5.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# DataFrame，其中的x是DataFrame中列或者行，是Series\n",
    "df = df.apply(lambda x : x.median(),axis = 0) # 列的中位数\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "e0f25573",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       0           4      4\n",
       "B       3           5      0\n",
       "C       8           6      6\n",
       "D       0           0      3\n",
       "E       9           9      0\n",
       "F       7           5      8\n",
       "H       5           2      6\n",
       "I       2           6      4\n",
       "J       2           2      7\n",
       "K       8           6      2"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "    index = list('ABCDEFHIJK'),\n",
    "    columns=['Python','Tensorflow','Keras'])\n",
    "df "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "09e1d008",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    (2.7, 3)\n",
       "B    (2.7, 3)\n",
       "C    (6.7, 3)\n",
       "D    (1.0, 3)\n",
       "E    (6.0, 3)\n",
       "F    (6.7, 3)\n",
       "H    (4.3, 3)\n",
       "I    (4.0, 3)\n",
       "J    (3.7, 3)\n",
       "K    (5.3, 3)\n",
       "dtype: object"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def convert(x): # 自定义方法\n",
    "    return (x.mean().round(1),x.count())\n",
    "df = df.apply(convert,axis = 1) # 行平均值，计数\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "df6888ec",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       4           8      4\n",
       "B       0           2      7\n",
       "C       5           5      5\n",
       "D       1           5      4\n",
       "E       0           2      6\n",
       "F       8           3      2\n",
       "H       7           4      0\n",
       "I       2           4      3\n",
       "J       9           9      9\n",
       "K       9           4      8"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "    index = list('ABCDEFHIJK'),\n",
    "    columns=['Python','Tensorflow','Keras'])\n",
    "df "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "40084d31",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>104</td>\n",
       "      <td>108</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>100</td>\n",
       "      <td>102</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>105</td>\n",
       "      <td>105</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>101</td>\n",
       "      <td>105</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>100</td>\n",
       "      <td>102</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>108</td>\n",
       "      <td>103</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>107</td>\n",
       "      <td>104</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>104</td>\n",
       "      <td>103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>109</td>\n",
       "      <td>109</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>109</td>\n",
       "      <td>104</td>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     104         108    104\n",
       "B     100         102    107\n",
       "C     105         105    105\n",
       "D     101         105    104\n",
       "E     100         102    106\n",
       "F     108         103    102\n",
       "H     107         104    100\n",
       "I     102         104    103\n",
       "J     109         109    109\n",
       "K     109         104    108"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、applymap DataFrame专有\n",
    "df = df.applymap(lambda x : x + 100) # 计算DataFrame中每个元素\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17b5c73d",
   "metadata": {
    "hidden": true
   },
   "source": [
    "##  transform变形金刚"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "5c511ee9",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       9           7    4.0\n",
       "B       4           6    5.0\n",
       "C       8           3    7.0\n",
       "D       2           1    0.0\n",
       "E       1           7    NaN\n",
       "F       1           6    2.0\n",
       "H       5           1    8.0\n",
       "I       5           8    9.0\n",
       "J       3           9    1.0\n",
       "K       2           2    4.0"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df.iloc[4,2] = None # 空数据\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "bd395ad3",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sqrt</th>\n",
       "      <th>exp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>8103.083928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>54.598150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>2.828427</td>\n",
       "      <td>2980.957987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.718282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.718282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1.732051</td>\n",
       "      <td>20.085537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sqrt          exp\n",
       "A  3.000000  8103.083928\n",
       "B  2.000000    54.598150\n",
       "C  2.828427  2980.957987\n",
       "D  1.414214     7.389056\n",
       "E  1.000000     2.718282\n",
       "F  1.000000     2.718282\n",
       "H  2.236068   148.413159\n",
       "I  2.236068   148.413159\n",
       "J  1.732051    20.085537\n",
       "K  1.414214     7.389056"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、一列执行多项计算\n",
    "df['Python'].transform([np.sqrt,np.exp]) # Series处理\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "fe095b87",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>7</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       3           9      5\n",
       "B       0           9      7\n",
       "C       2           3      3\n",
       "D       9           9      6\n",
       "E       6           6      0\n",
       "F       0           8      6\n",
       "H       9           0      8\n",
       "I       3           3      2\n",
       "J       9           7      8\n",
       "K       7           6      0"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def convert(x):\n",
    "    if x.mean() > 5:\n",
    "        x *= 10\n",
    "    else:\n",
    "        x *= -10\n",
    "    return x\n",
    "\n",
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "4c13ba59",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>3000000</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0</td>\n",
       "      <td>18</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>2000000</td>\n",
       "      <td>21</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>9000000</td>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>6000000</td>\n",
       "      <td>36</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>0</td>\n",
       "      <td>44</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>9000000</td>\n",
       "      <td>44</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>3000000</td>\n",
       "      <td>47</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>9000000</td>\n",
       "      <td>54</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>7000000</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "A  3000000           9      5\n",
       "B        0          18      7\n",
       "C  2000000          21      3\n",
       "D  9000000          30      6\n",
       "E  6000000          36      0\n",
       "F        0          44      6\n",
       "H  9000000          44      8\n",
       "I  3000000          47      2\n",
       "J  9000000          54      8\n",
       "K  7000000          60      0"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.transform({'Python':convert,'Tensorflow':np.cumsum,'Keras':np.abs}) # DataFrame处理\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "ceb1eb8e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9000000"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].max(axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59e347a4",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 重排随机抽样哑变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "db99f3e5",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       1           1      0\n",
       "B       8           7      4\n",
       "C       5           5      6\n",
       "D       4           8      4\n",
       "E       0           9      0\n",
       "F       8           3      4\n",
       "H       0           3      3\n",
       "I       5           7      5\n",
       "J       3           2      4\n",
       "K       8           8      9"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "id": "0340703c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "K       8           8      9\n",
       "J       3           2      4\n",
       "H       0           3      3\n",
       "C       5           5      6\n",
       "E       0           9      0\n",
       "D       4           8      4\n",
       "B       8           7      4\n",
       "I       5           7      5\n",
       "A       1           1      0\n",
       "F       8           3      4"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = np.random.permutation(10) # 随机重排\n",
    "df.take(index) # 重排DataFrame,索引打乱"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "id": "22f3499a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "J       3           2      4\n",
       "E       0           9      0\n",
       "E       0           9      0\n",
       "C       5           5      6\n",
       "B       8           7      4\n",
       "C       5           5      6\n",
       "C       5           5      6\n",
       "F       8           3      4\n",
       "H       0           3      3\n",
       "E       0           9      0\n",
       "B       8           7      4\n",
       "B       8           7      4\n",
       "C       5           5      6\n",
       "J       3           2      4\n",
       "H       0           3      3"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.take(np.random.randint(0,10,size = 15)) # 随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "id": "98dd899c",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   a  b  c\n",
       "0  0  1  0\n",
       "1  0  1  0\n",
       "2  1  0  0\n",
       "3  0  0  1\n",
       "4  1  0  0\n",
       "5  0  1  0"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 哑变量，独热编码，1表示有，0表示没有\n",
    "df = pd.DataFrame({'key':['b','b','a','c','a','b']})\n",
    "pd.get_dummies(df,prefix='',prefix_sep='')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "582f9cd9",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数据重塑"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0939cb8",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## panads数据重塑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "c8f0daf5",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,100,size = (10,3)),\n",
    "        index = list('ABCDEFHIJK'),\n",
    "        columns=['Python','Tensorflow','Keras'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "id": "417e7e40",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>H</th>\n",
       "      <th>I</th>\n",
       "      <th>J</th>\n",
       "      <th>K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>10</td>\n",
       "      <td>78</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>65</td>\n",
       "      <td>35</td>\n",
       "      <td>74</td>\n",
       "      <td>27</td>\n",
       "      <td>91</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>19</td>\n",
       "      <td>53</td>\n",
       "      <td>54</td>\n",
       "      <td>31</td>\n",
       "      <td>66</td>\n",
       "      <td>95</td>\n",
       "      <td>98</td>\n",
       "      <td>58</td>\n",
       "      <td>13</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>53</td>\n",
       "      <td>55</td>\n",
       "      <td>78</td>\n",
       "      <td>65</td>\n",
       "      <td>89</td>\n",
       "      <td>76</td>\n",
       "      <td>4</td>\n",
       "      <td>35</td>\n",
       "      <td>91</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             A   B   C   D   E   F   H   I   J   K\n",
       "Python      10  78  25   2  65  35  74  27  91  59\n",
       "Tensorflow  19  53  54  31  66  95  98  58  13  92\n",
       "Keras       53  55  78  65  89  76   4  35  91  56"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "6d2ab897",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">A</th>\n",
       "      <th>期中</th>\n",
       "      <td>62</td>\n",
       "      <td>75</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">B</th>\n",
       "      <th>期中</th>\n",
       "      <td>44</td>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>6</td>\n",
       "      <td>46</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">C</th>\n",
       "      <th>期中</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>85</td>\n",
       "      <td>49</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">D</th>\n",
       "      <th>期中</th>\n",
       "      <td>9</td>\n",
       "      <td>32</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>20</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">E</th>\n",
       "      <th>期中</th>\n",
       "      <td>98</td>\n",
       "      <td>55</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>22</td>\n",
       "      <td>58</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">F</th>\n",
       "      <th>期中</th>\n",
       "      <td>12</td>\n",
       "      <td>72</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>41</td>\n",
       "      <td>24</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">H</th>\n",
       "      <th>期中</th>\n",
       "      <td>70</td>\n",
       "      <td>40</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>21</td>\n",
       "      <td>52</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">I</th>\n",
       "      <th>期中</th>\n",
       "      <td>33</td>\n",
       "      <td>28</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>61</td>\n",
       "      <td>20</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">J</th>\n",
       "      <th>期中</th>\n",
       "      <td>73</td>\n",
       "      <td>48</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>73</td>\n",
       "      <td>40</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">K</th>\n",
       "      <th>期中</th>\n",
       "      <td>82</td>\n",
       "      <td>62</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>33</td>\n",
       "      <td>84</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Python  Tensorflow  Keras\n",
       "A 期中      62          75     66\n",
       "  期末      72          69     81\n",
       "B 期中      44           4     21\n",
       "  期末       6          46     19\n",
       "C 期中      96          99     58\n",
       "  期末      85          49     21\n",
       "D 期中       9          32     16\n",
       "  期末      20          58     58\n",
       "E 期中      98          55     84\n",
       "  期末      22          58      7\n",
       "F 期中      12          72     67\n",
       "  期末      41          24     63\n",
       "H 期中      70          40     78\n",
       "  期末      21          52     67\n",
       "I 期中      33          28     69\n",
       "  期末      61          20     34\n",
       "J 期中      73          48     75\n",
       "  期末      73          40     46\n",
       "K 期中      82          62     72\n",
       "  期末      33          84     37"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.DataFrame(data = np.random.randint(0,100,size = (20,3)),\n",
    "        index = pd.MultiIndex.from_product([list('ABCDEFHIJK'),['期中','期末']]),#多层索引\n",
    "        columns=['Python','Tensorflow','Keras'])    \n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "id": "322c43f9",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Python</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Tensorflow</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Keras</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>期中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期中</th>\n",
       "      <th>期末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>62</td>\n",
       "      <td>72</td>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "      <td>66</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>44</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>46</td>\n",
       "      <td>21</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>96</td>\n",
       "      <td>85</td>\n",
       "      <td>99</td>\n",
       "      <td>49</td>\n",
       "      <td>58</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>9</td>\n",
       "      <td>20</td>\n",
       "      <td>32</td>\n",
       "      <td>58</td>\n",
       "      <td>16</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>98</td>\n",
       "      <td>22</td>\n",
       "      <td>55</td>\n",
       "      <td>58</td>\n",
       "      <td>84</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>12</td>\n",
       "      <td>41</td>\n",
       "      <td>72</td>\n",
       "      <td>24</td>\n",
       "      <td>67</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>21</td>\n",
       "      <td>40</td>\n",
       "      <td>52</td>\n",
       "      <td>78</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>33</td>\n",
       "      <td>61</td>\n",
       "      <td>28</td>\n",
       "      <td>20</td>\n",
       "      <td>69</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>73</td>\n",
       "      <td>73</td>\n",
       "      <td>48</td>\n",
       "      <td>40</td>\n",
       "      <td>75</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>82</td>\n",
       "      <td>33</td>\n",
       "      <td>62</td>\n",
       "      <td>84</td>\n",
       "      <td>72</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Python     Tensorflow     Keras    \n",
       "      期中  期末         期中  期末    期中  期末\n",
       "A     62  72         75  69    66  81\n",
       "B     44   6          4  46    21  19\n",
       "C     96  85         99  49    58  21\n",
       "D      9  20         32  58    16  58\n",
       "E     98  22         55  58    84   7\n",
       "F     12  41         72  24    67  63\n",
       "H     70  21         40  52    78  67\n",
       "I     33  61         28  20    69  34\n",
       "J     73  73         48  40    75  46\n",
       "K     82  33         62  84    72  37"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.unstack(level = -1) # 行旋转成列，level指定哪一层，进行变换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "926f107e",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A  期中  Python        62\n",
       "       Tensorflow    75\n",
       "       Keras         66\n",
       "   期末  Python        72\n",
       "       Tensorflow    69\n",
       "       Keras         81\n",
       "B  期中  Python        44\n",
       "       Tensorflow     4\n",
       "       Keras         21\n",
       "   期末  Python         6\n",
       "       Tensorflow    46\n",
       "       Keras         19\n",
       "C  期中  Python        96\n",
       "       Tensorflow    99\n",
       "       Keras         58\n",
       "   期末  Python        85\n",
       "       Tensorflow    49\n",
       "       Keras         21\n",
       "D  期中  Python         9\n",
       "       Tensorflow    32\n",
       "       Keras         16\n",
       "   期末  Python        20\n",
       "       Tensorflow    58\n",
       "       Keras         58\n",
       "E  期中  Python        98\n",
       "       Tensorflow    55\n",
       "       Keras         84\n",
       "   期末  Python        22\n",
       "       Tensorflow    58\n",
       "       Keras          7\n",
       "F  期中  Python        12\n",
       "       Tensorflow    72\n",
       "       Keras         67\n",
       "   期末  Python        41\n",
       "       Tensorflow    24\n",
       "       Keras         63\n",
       "H  期中  Python        70\n",
       "       Tensorflow    40\n",
       "       Keras         78\n",
       "   期末  Python        21\n",
       "       Tensorflow    52\n",
       "       Keras         67\n",
       "I  期中  Python        33\n",
       "       Tensorflow    28\n",
       "       Keras         69\n",
       "   期末  Python        61\n",
       "       Tensorflow    20\n",
       "       Keras         34\n",
       "J  期中  Python        73\n",
       "       Tensorflow    48\n",
       "       Keras         75\n",
       "   期末  Python        73\n",
       "       Tensorflow    40\n",
       "       Keras         46\n",
       "K  期中  Python        82\n",
       "       Tensorflow    62\n",
       "       Keras         72\n",
       "   期末  Python        33\n",
       "       Tensorflow    84\n",
       "       Keras         37\n",
       "dtype: int32"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.stack() # 列旋转成行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "id": "ca048463",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>期中</th>\n",
       "      <th>期末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">A</th>\n",
       "      <th>Python</th>\n",
       "      <td>62</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>66</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">B</th>\n",
       "      <th>Python</th>\n",
       "      <td>44</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>4</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>21</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">C</th>\n",
       "      <th>Python</th>\n",
       "      <td>96</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>99</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>58</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">D</th>\n",
       "      <th>Python</th>\n",
       "      <td>9</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>32</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>16</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">E</th>\n",
       "      <th>Python</th>\n",
       "      <td>98</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>55</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>84</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">F</th>\n",
       "      <th>Python</th>\n",
       "      <td>12</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>72</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>67</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">H</th>\n",
       "      <th>Python</th>\n",
       "      <td>70</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>40</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>78</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">I</th>\n",
       "      <th>Python</th>\n",
       "      <td>33</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>28</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>69</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">J</th>\n",
       "      <th>Python</th>\n",
       "      <td>73</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>48</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>75</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">K</th>\n",
       "      <th>Python</th>\n",
       "      <td>82</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>62</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>72</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              期中  期末\n",
       "A Python      62  72\n",
       "  Tensorflow  75  69\n",
       "  Keras       66  81\n",
       "B Python      44   6\n",
       "  Tensorflow   4  46\n",
       "  Keras       21  19\n",
       "C Python      96  85\n",
       "  Tensorflow  99  49\n",
       "  Keras       58  21\n",
       "D Python       9  20\n",
       "  Tensorflow  32  58\n",
       "  Keras       16  58\n",
       "E Python      98  22\n",
       "  Tensorflow  55  58\n",
       "  Keras       84   7\n",
       "F Python      12  41\n",
       "  Tensorflow  72  24\n",
       "  Keras       67  63\n",
       "H Python      70  21\n",
       "  Tensorflow  40  52\n",
       "  Keras       78  67\n",
       "I Python      33  61\n",
       "  Tensorflow  28  20\n",
       "  Keras       69  34\n",
       "J Python      73  73\n",
       "  Tensorflow  48  40\n",
       "  Keras       75  46\n",
       "K Python      82  33\n",
       "  Tensorflow  62  84\n",
       "  Keras       72  37"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.stack().unstack(level = 1) # 行列互换\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "id": "2fda52f6",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        50.65\n",
       "Tensorflow    50.75\n",
       "Keras         51.95\n",
       "dtype: float64"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 多层索引DataFrame数学计算\n",
    "df2.mean() # 各学科平均分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "a80ed39a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lenovo\\AppData\\Local\\Temp/ipykernel_20936/3816846524.py:1: FutureWarning: Using the level keyword in DataFrame and Series aggregations is deprecated and will be removed in a future version. Use groupby instead. df.median(level=1) should use df.groupby(level=1).median().\n",
      "  df2.mean(level=0) # 各学科，每个人期中期末平均分\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>67.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>73.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>25.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>90.5</td>\n",
       "      <td>74.0</td>\n",
       "      <td>39.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>14.5</td>\n",
       "      <td>45.0</td>\n",
       "      <td>37.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>60.0</td>\n",
       "      <td>56.5</td>\n",
       "      <td>45.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26.5</td>\n",
       "      <td>48.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>45.5</td>\n",
       "      <td>46.0</td>\n",
       "      <td>72.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>47.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>51.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>73.0</td>\n",
       "      <td>44.0</td>\n",
       "      <td>60.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>57.5</td>\n",
       "      <td>73.0</td>\n",
       "      <td>54.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A    67.0        72.0   73.5\n",
       "B    25.0        25.0   20.0\n",
       "C    90.5        74.0   39.5\n",
       "D    14.5        45.0   37.0\n",
       "E    60.0        56.5   45.5\n",
       "F    26.5        48.0   65.0\n",
       "H    45.5        46.0   72.5\n",
       "I    47.0        24.0   51.5\n",
       "J    73.0        44.0   60.5\n",
       "K    57.5        73.0   54.5"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.mean(level=0) # 各学科，每个人期中期末平均分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "id": "4ed26840",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\lenovo\\AppData\\Local\\Temp/ipykernel_20936/3305433236.py:1: FutureWarning: Using the level keyword in DataFrame and Series aggregations is deprecated and will be removed in a future version. Use groupby instead. df.median(level=1) should use df.groupby(level=1).median().\n",
      "  df2.mean(level = 1) # 各学科，期中期末所有人平均分\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>期中</th>\n",
       "      <td>57.9</td>\n",
       "      <td>51.5</td>\n",
       "      <td>60.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>43.4</td>\n",
       "      <td>50.0</td>\n",
       "      <td>43.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "期中    57.9        51.5   60.6\n",
       "期末    43.4        50.0   43.3"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.mean(level = 1) # 各学科，期中期末所有人平均分"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db37c00a",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数学和统计方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b00f3bc5",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 简单统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "d91d4112",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>25</td>\n",
       "      <td>56</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>71</td>\n",
       "      <td>14</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>95</td>\n",
       "      <td>36</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>89</td>\n",
       "      <td>26</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>60</td>\n",
       "      <td>53</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>25</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>98</td>\n",
       "      <td>41</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>64</td>\n",
       "      <td>43</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>88</td>\n",
       "      <td>92</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>69</td>\n",
       "      <td>68</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>38</td>\n",
       "      <td>83</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>42</td>\n",
       "      <td>35</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>73</td>\n",
       "      <td>87</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>61</td>\n",
       "      <td>25</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>46</td>\n",
       "      <td>96</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>41</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>86</td>\n",
       "      <td>6</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      18          22     19\n",
       "B      25          56     13\n",
       "C      71          14     56\n",
       "D      95          36     55\n",
       "E      89          26     96\n",
       "F      85          92     72\n",
       "H      60          53     13\n",
       "I      25          73     42\n",
       "J      98          41     54\n",
       "K      64          43     44\n",
       "L      88          92     15\n",
       "M      69          68     96\n",
       "N      38          83     72\n",
       "O      42          35     53\n",
       "P      73          87     46\n",
       "Q       7          76     80\n",
       "R      61          25     52\n",
       "S      46          96      8\n",
       "T      41           0     38\n",
       "U      86           6     18"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,100,size = (20,3)),\n",
    "    index = list('ABCDEFHIJKLMNOPQRSTU'),\n",
    "    columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "id": "c8f36acf",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        20\n",
       "Tensorflow    20\n",
       "Keras         20\n",
       "dtype: int64"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、简单统计指标\n",
    "df.count() # 非NA值的数量\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "id": "a5b865e2",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        98\n",
       "Tensorflow    96\n",
       "Keras         96\n",
       "dtype: int32"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.max(axis = 0) #轴0最大值，即每一列最大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "id": "836d0772",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        7\n",
       "Tensorflow    0\n",
       "Keras         8\n",
       "dtype: int32"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.min() #默认计算轴0最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "id": "6d1cf9cd",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        62.5\n",
       "Tensorflow    48.0\n",
       "Keras         49.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.median() # 中位数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "id": "d5128fb1",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        1181\n",
       "Tensorflow    1024\n",
       "Keras          942\n",
       "dtype: int64"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sum() # 求和\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "id": "d6f57a75",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    19.666667\n",
       "B    31.333333\n",
       "C    47.000000\n",
       "D    62.000000\n",
       "E    70.333333\n",
       "F    83.000000\n",
       "H    42.000000\n",
       "I    46.666667\n",
       "J    64.333333\n",
       "K    50.333333\n",
       "L    65.000000\n",
       "M    77.666667\n",
       "N    64.333333\n",
       "O    43.333333\n",
       "P    68.666667\n",
       "Q    54.333333\n",
       "R    46.000000\n",
       "S    50.000000\n",
       "T    26.333333\n",
       "U    36.666667\n",
       "dtype: float64"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.mean(axis = 1) #轴1平均值，即每一行的平均值\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "a1ff564e",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0.2</th>\n",
       "      <td>35.4</td>\n",
       "      <td>24.4</td>\n",
       "      <td>17.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.4</th>\n",
       "      <td>54.4</td>\n",
       "      <td>39.0</td>\n",
       "      <td>43.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.8</th>\n",
       "      <td>86.4</td>\n",
       "      <td>83.8</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Tensorflow  Keras\n",
       "0.2    35.4        24.4   17.4\n",
       "0.4    54.4        39.0   43.2\n",
       "0.8    86.4        83.8   72.0"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.quantile(q = [0.2,0.4,0.8]) # 分位数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "3d57a6e1",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>59.050000</td>\n",
       "      <td>51.200000</td>\n",
       "      <td>47.100000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>27.484876</td>\n",
       "      <td>30.706762</td>\n",
       "      <td>27.138824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>8.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>40.250000</td>\n",
       "      <td>25.750000</td>\n",
       "      <td>18.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>62.500000</td>\n",
       "      <td>48.000000</td>\n",
       "      <td>49.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>85.250000</td>\n",
       "      <td>77.750000</td>\n",
       "      <td>60.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>98.000000</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>96.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Python  Tensorflow      Keras\n",
       "count  20.000000   20.000000  20.000000\n",
       "mean   59.050000   51.200000  47.100000\n",
       "std    27.484876   30.706762  27.138824\n",
       "min     7.000000    0.000000   8.000000\n",
       "25%    40.250000   25.750000  18.750000\n",
       "50%    62.500000   48.000000  49.000000\n",
       "75%    85.250000   77.750000  60.000000\n",
       "max    98.000000   96.000000  96.000000"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe() # 查看数值型列的汇总统计,计数、平均值、标准差、最小值、四分位数、最大值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "740fae9a",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 索引标签、位置获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "fa6d10c2",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、索引位置\n",
    "df['Python'].argmin() # 计算最小值位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "id": "e0f7f1bc",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Keras'].argmax() # 最大值位置\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "e2cf5e13",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        J\n",
       "Tensorflow    S\n",
       "Keras         E\n",
       "dtype: object"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.idxmax() # 最大值索引标签"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "id": "826a954e",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        Q\n",
       "Tensorflow    T\n",
       "Keras         S\n",
       "dtype: object"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.idxmin() # 最小值索引标签"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8dc60790",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 更多统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "f4f1a5d6",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25    2\n",
       "18    1\n",
       "69    1\n",
       "41    1\n",
       "46    1\n",
       "61    1\n",
       "7     1\n",
       "73    1\n",
       "42    1\n",
       "38    1\n",
       "88    1\n",
       "64    1\n",
       "98    1\n",
       "60    1\n",
       "85    1\n",
       "89    1\n",
       "95    1\n",
       "71    1\n",
       "86    1\n",
       "Name: Python, dtype: int64"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、更多统计指标\n",
    "df['Python'].value_counts() # 统计元素出现次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "e5f02b3e",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([19, 13, 56, 55, 96, 72, 42, 54, 44, 15, 53, 46, 80, 52,  8, 38, 18])"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Keras'].unique() # 去重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "6b199e2a",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>43</td>\n",
       "      <td>78</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>114</td>\n",
       "      <td>92</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>209</td>\n",
       "      <td>128</td>\n",
       "      <td>143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>298</td>\n",
       "      <td>154</td>\n",
       "      <td>239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>383</td>\n",
       "      <td>246</td>\n",
       "      <td>311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>443</td>\n",
       "      <td>299</td>\n",
       "      <td>324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>468</td>\n",
       "      <td>372</td>\n",
       "      <td>366</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>566</td>\n",
       "      <td>413</td>\n",
       "      <td>420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>630</td>\n",
       "      <td>456</td>\n",
       "      <td>464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>718</td>\n",
       "      <td>548</td>\n",
       "      <td>479</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>787</td>\n",
       "      <td>616</td>\n",
       "      <td>575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>825</td>\n",
       "      <td>699</td>\n",
       "      <td>647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>867</td>\n",
       "      <td>734</td>\n",
       "      <td>700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>940</td>\n",
       "      <td>821</td>\n",
       "      <td>746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>947</td>\n",
       "      <td>897</td>\n",
       "      <td>826</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>1008</td>\n",
       "      <td>922</td>\n",
       "      <td>878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>1054</td>\n",
       "      <td>1018</td>\n",
       "      <td>886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>1095</td>\n",
       "      <td>1018</td>\n",
       "      <td>924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>1181</td>\n",
       "      <td>1024</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      18          22     19\n",
       "B      43          78     32\n",
       "C     114          92     88\n",
       "D     209         128    143\n",
       "E     298         154    239\n",
       "F     383         246    311\n",
       "H     443         299    324\n",
       "I     468         372    366\n",
       "J     566         413    420\n",
       "K     630         456    464\n",
       "L     718         548    479\n",
       "M     787         616    575\n",
       "N     825         699    647\n",
       "O     867         734    700\n",
       "P     940         821    746\n",
       "Q     947         897    826\n",
       "R    1008         922    878\n",
       "S    1054        1018    886\n",
       "T    1095        1018    924\n",
       "U    1181        1024    942"
      ]
     },
     "execution_count": 220,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumsum() # 累加\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "28548dd9",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>450</td>\n",
       "      <td>1232</td>\n",
       "      <td>247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>31950</td>\n",
       "      <td>17248</td>\n",
       "      <td>13832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3035250</td>\n",
       "      <td>620928</td>\n",
       "      <td>760760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>270137250</td>\n",
       "      <td>16144128</td>\n",
       "      <td>73032960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1486829770</td>\n",
       "      <td>1485259776</td>\n",
       "      <td>963405824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-984527016</td>\n",
       "      <td>1409356800</td>\n",
       "      <td>-360626176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>1156628376</td>\n",
       "      <td>-196168704</td>\n",
       "      <td>2033569792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1680431152</td>\n",
       "      <td>547017728</td>\n",
       "      <td>-1856380928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>173411328</td>\n",
       "      <td>2046925824</td>\n",
       "      <td>-76382208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>-1919672320</td>\n",
       "      <td>-661385216</td>\n",
       "      <td>-1145733120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>686596096</td>\n",
       "      <td>-2024521728</td>\n",
       "      <td>1678770176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>320847872</td>\n",
       "      <td>-531578880</td>\n",
       "      <td>612368384</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>590708736</td>\n",
       "      <td>-1425391616</td>\n",
       "      <td>-1904214016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>172064768</td>\n",
       "      <td>544980992</td>\n",
       "      <td>-1694498816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>1204453376</td>\n",
       "      <td>-1531117568</td>\n",
       "      <td>1879048192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>457211904</td>\n",
       "      <td>376766464</td>\n",
       "      <td>-1073741824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>-443088896</td>\n",
       "      <td>1809842176</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-986775552</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>1036648448</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Python  Tensorflow       Keras\n",
       "A          18          22          19\n",
       "B         450        1232         247\n",
       "C       31950       17248       13832\n",
       "D     3035250      620928      760760\n",
       "E   270137250    16144128    73032960\n",
       "F  1486829770  1485259776   963405824\n",
       "H  -984527016  1409356800  -360626176\n",
       "I  1156628376  -196168704  2033569792\n",
       "J  1680431152   547017728 -1856380928\n",
       "K   173411328  2046925824   -76382208\n",
       "L -1919672320  -661385216 -1145733120\n",
       "M   686596096 -2024521728  1678770176\n",
       "N   320847872  -531578880   612368384\n",
       "O   590708736 -1425391616 -1904214016\n",
       "P   172064768   544980992 -1694498816\n",
       "Q  1204453376 -1531117568  1879048192\n",
       "R   457211904   376766464 -1073741824\n",
       "S  -443088896  1809842176           0\n",
       "T  -986775552           0           0\n",
       "U  1036648448           0           0"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumprod() # 累乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "4b630609",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        27.484876\n",
       "Tensorflow    30.706762\n",
       "Keras         27.138824\n",
       "dtype: float64"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.std() # 标准差\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "b7e91d13",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        755.418421\n",
       "Tensorflow    942.905263\n",
       "Keras         736.515789\n",
       "dtype: float64"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.var() # 方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "54e9ad4a",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>7</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>7</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>7</td>\n",
       "      <td>14</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      18          22     19\n",
       "B      18          22     13\n",
       "C      18          14     13\n",
       "D      18          14     13\n",
       "E      18          14     13\n",
       "F      18          14     13\n",
       "H      18          14     13\n",
       "I      18          14     13\n",
       "J      18          14     13\n",
       "K      18          14     13\n",
       "L      18          14     13\n",
       "M      18          14     13\n",
       "N      18          14     13\n",
       "O      18          14     13\n",
       "P      18          14     13\n",
       "Q       7          14     13\n",
       "R       7          14     13\n",
       "S       7          14      8\n",
       "T       7           0      8\n",
       "U       7           0      8"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cummin() # 累计最小值\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "id": "ed4d93c2",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>18</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>25</td>\n",
       "      <td>56</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>71</td>\n",
       "      <td>56</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>95</td>\n",
       "      <td>56</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>95</td>\n",
       "      <td>56</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>98</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>98</td>\n",
       "      <td>96</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>98</td>\n",
       "      <td>96</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>98</td>\n",
       "      <td>96</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      18          22     19\n",
       "B      25          56     19\n",
       "C      71          56     56\n",
       "D      95          56     56\n",
       "E      95          56     96\n",
       "F      95          92     96\n",
       "H      95          92     96\n",
       "I      95          92     96\n",
       "J      98          92     96\n",
       "K      98          92     96\n",
       "L      98          92     96\n",
       "M      98          92     96\n",
       "N      98          92     96\n",
       "O      98          92     96\n",
       "P      98          92     96\n",
       "Q      98          92     96\n",
       "R      98          92     96\n",
       "S      98          96     96\n",
       "T      98          96     96\n",
       "U      98          96     96"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cummax() # 累计最大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "958d86c3",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>7.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>-6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>46.0</td>\n",
       "      <td>-42.0</td>\n",
       "      <td>43.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>24.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-6.0</td>\n",
       "      <td>-10.0</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-4.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>-24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-25.0</td>\n",
       "      <td>-39.0</td>\n",
       "      <td>-59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-35.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>73.0</td>\n",
       "      <td>-32.0</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>-34.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>24.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>-29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>-19.0</td>\n",
       "      <td>-24.0</td>\n",
       "      <td>81.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>-31.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>-24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>4.0</td>\n",
       "      <td>-48.0</td>\n",
       "      <td>-19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>31.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>-7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>-66.0</td>\n",
       "      <td>-11.0</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>54.0</td>\n",
       "      <td>-51.0</td>\n",
       "      <td>-28.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>-15.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>-44.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-5.0</td>\n",
       "      <td>-96.0</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>45.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>-20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     NaN         NaN    NaN\n",
       "B     7.0        34.0   -6.0\n",
       "C    46.0       -42.0   43.0\n",
       "D    24.0        22.0   -1.0\n",
       "E    -6.0       -10.0   41.0\n",
       "F    -4.0        66.0  -24.0\n",
       "H   -25.0       -39.0  -59.0\n",
       "I   -35.0        20.0   29.0\n",
       "J    73.0       -32.0   12.0\n",
       "K   -34.0         2.0  -10.0\n",
       "L    24.0        49.0  -29.0\n",
       "M   -19.0       -24.0   81.0\n",
       "N   -31.0        15.0  -24.0\n",
       "O     4.0       -48.0  -19.0\n",
       "P    31.0        52.0   -7.0\n",
       "Q   -66.0       -11.0   34.0\n",
       "R    54.0       -51.0  -28.0\n",
       "S   -15.0        71.0  -44.0\n",
       "T    -5.0       -96.0   30.0\n",
       "U    45.0         6.0  -20.0"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.diff() # 计算差分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "60f4e6e2",
   "metadata": {
    "collapsed": true,
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0.388889</td>\n",
       "      <td>1.545455</td>\n",
       "      <td>-0.315789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1.840000</td>\n",
       "      <td>-0.750000</td>\n",
       "      <td>3.307692</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.338028</td>\n",
       "      <td>1.571429</td>\n",
       "      <td>-0.017857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-0.063158</td>\n",
       "      <td>-0.277778</td>\n",
       "      <td>0.745455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-0.044944</td>\n",
       "      <td>2.538462</td>\n",
       "      <td>-0.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-0.294118</td>\n",
       "      <td>-0.423913</td>\n",
       "      <td>-0.819444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-0.583333</td>\n",
       "      <td>0.377358</td>\n",
       "      <td>2.230769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>2.920000</td>\n",
       "      <td>-0.438356</td>\n",
       "      <td>0.285714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>-0.346939</td>\n",
       "      <td>0.048780</td>\n",
       "      <td>-0.185185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>0.375000</td>\n",
       "      <td>1.139535</td>\n",
       "      <td>-0.659091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>-0.215909</td>\n",
       "      <td>-0.260870</td>\n",
       "      <td>5.400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>-0.449275</td>\n",
       "      <td>0.220588</td>\n",
       "      <td>-0.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>0.105263</td>\n",
       "      <td>-0.578313</td>\n",
       "      <td>-0.263889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>0.738095</td>\n",
       "      <td>1.485714</td>\n",
       "      <td>-0.132075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>-0.904110</td>\n",
       "      <td>-0.126437</td>\n",
       "      <td>0.739130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>7.714286</td>\n",
       "      <td>-0.671053</td>\n",
       "      <td>-0.350000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>-0.245902</td>\n",
       "      <td>2.840000</td>\n",
       "      <td>-0.846154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-0.108696</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>3.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>1.097561</td>\n",
       "      <td>inf</td>\n",
       "      <td>-0.526316</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Tensorflow     Keras\n",
       "A       NaN         NaN       NaN\n",
       "B  0.388889    1.545455 -0.315789\n",
       "C  1.840000   -0.750000  3.307692\n",
       "D  0.338028    1.571429 -0.017857\n",
       "E -0.063158   -0.277778  0.745455\n",
       "F -0.044944    2.538462 -0.250000\n",
       "H -0.294118   -0.423913 -0.819444\n",
       "I -0.583333    0.377358  2.230769\n",
       "J  2.920000   -0.438356  0.285714\n",
       "K -0.346939    0.048780 -0.185185\n",
       "L  0.375000    1.139535 -0.659091\n",
       "M -0.215909   -0.260870  5.400000\n",
       "N -0.449275    0.220588 -0.250000\n",
       "O  0.105263   -0.578313 -0.263889\n",
       "P  0.738095    1.485714 -0.132075\n",
       "Q -0.904110   -0.126437  0.739130\n",
       "R  7.714286   -0.671053 -0.350000\n",
       "S -0.245902    2.840000 -0.846154\n",
       "T -0.108696   -1.000000  3.750000\n",
       "U  1.097561         inf -0.526316"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pct_change() # 计算百分比变化\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6f59ed4",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 高级统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "6028cf80",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>755.418421</td>\n",
       "      <td>-84.010526</td>\n",
       "      <td>121.836842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>-84.010526</td>\n",
       "      <td>942.905263</td>\n",
       "      <td>34.610526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>121.836842</td>\n",
       "      <td>34.610526</td>\n",
       "      <td>736.515789</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Python  Tensorflow       Keras\n",
       "Python      755.418421  -84.010526  121.836842\n",
       "Tensorflow  -84.010526  942.905263   34.610526\n",
       "Keras       121.836842   34.610526  736.515789"
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4、高级统计指标\n",
    "df.cov() # 属性的协方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "89fbdcf4",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "121.83684210526309"
      ]
     },
     "execution_count": 229,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].cov(df['Keras']) # Python和Keras的协方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "b558715b",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.099542</td>\n",
       "      <td>0.163340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>-0.099542</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.041532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>0.163340</td>\n",
       "      <td>0.041532</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Python  Tensorflow     Keras\n",
       "Python      1.000000   -0.099542  0.163340\n",
       "Tensorflow -0.099542    1.000000  0.041532\n",
       "Keras       0.163340    0.041532  1.000000"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corr() # 所有属性相关性系数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "id": "e33a427a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python       -0.099542\n",
       "Tensorflow    1.000000\n",
       "Keras         0.041532\n",
       "dtype: float64"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corrwith(df['Tensorflow']) # 单一属性相关性系数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3b8728a",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# 数据排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "010d0414",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>15</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>28</td>\n",
       "      <td>15</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>17</td>\n",
       "      <td>10</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>20</td>\n",
       "      <td>8</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "q      22     27        4\n",
       "w      15     20        5\n",
       "e      28     15       27\n",
       "r       1     24       12\n",
       "t      13     12        3\n",
       "y      22     27       19\n",
       "u       4     24       20\n",
       "i      17     10       19\n",
       "o      26     27        1\n",
       "i      27      5        6\n",
       "j      12     19        9\n",
       "h       0      9       28\n",
       "g      25     29        9\n",
       "f       1      1       11\n",
       "c      23     29        0\n",
       "a      14     20       19\n",
       "s      28     23       20\n",
       "d      21     24       19\n",
       "c       9      7       26\n",
       "v      16     26       23\n",
       "b      28     10        9\n",
       "n      13     22        1\n",
       "e       6     24        2\n",
       "r      11      0       27\n",
       "f      27     12       12\n",
       "g       1      4       14\n",
       "h      20      8       11\n",
       "j      14      2       13\n",
       "c       2     23        9\n",
       "f      26      9       15"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,30,size = (30,3)),\n",
    "        index = list('qwertyuioijhgfcasdcvbnerfghjcf'),\n",
    "        columns = ['Python','Keras','Pytorch'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "ad80c0bc",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>28</td>\n",
       "      <td>15</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>20</td>\n",
       "      <td>8</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>17</td>\n",
       "      <td>10</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>15</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "a      14     20       19\n",
       "b      28     10        9\n",
       "c      23     29        0\n",
       "c       9      7       26\n",
       "c       2     23        9\n",
       "d      21     24       19\n",
       "e      28     15       27\n",
       "e       6     24        2\n",
       "f      27     12       12\n",
       "f       1      1       11\n",
       "f      26      9       15\n",
       "g      25     29        9\n",
       "g       1      4       14\n",
       "h       0      9       28\n",
       "h      20      8       11\n",
       "i      27      5        6\n",
       "i      17     10       19\n",
       "j      14      2       13\n",
       "j      12     19        9\n",
       "n      13     22        1\n",
       "o      26     27        1\n",
       "q      22     27        4\n",
       "r       1     24       12\n",
       "r      11      0       27\n",
       "s      28     23       20\n",
       "t      13     12        3\n",
       "u       4     24       20\n",
       "v      16     26       23\n",
       "w      15     20        5\n",
       "y      22     27       19"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、索引列名排序\n",
    "df.sort_index(axis = 0,ascending=True) # 按索引排序，升序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "id": "ce0f333d",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pytorch</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>4</td>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>5</td>\n",
       "      <td>15</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>27</td>\n",
       "      <td>28</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>19</td>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>20</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>19</td>\n",
       "      <td>17</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>1</td>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>6</td>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>9</td>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>9</td>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>19</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>20</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>19</td>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>23</td>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>1</td>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>27</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>12</td>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>11</td>\n",
       "      <td>20</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>15</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Pytorch  Python  Keras\n",
       "q        4      22     27\n",
       "w        5      15     20\n",
       "e       27      28     15\n",
       "r       12       1     24\n",
       "t        3      13     12\n",
       "y       19      22     27\n",
       "u       20       4     24\n",
       "i       19      17     10\n",
       "o        1      26     27\n",
       "i        6      27      5\n",
       "j        9      12     19\n",
       "h       28       0      9\n",
       "g        9      25     29\n",
       "f       11       1      1\n",
       "c        0      23     29\n",
       "a       19      14     20\n",
       "s       20      28     23\n",
       "d       19      21     24\n",
       "c       26       9      7\n",
       "v       23      16     26\n",
       "b        9      28     10\n",
       "n        1      13     22\n",
       "e        2       6     24\n",
       "r       27      11      0\n",
       "f       12      27     12\n",
       "g       14       1      4\n",
       "h       11      20      8\n",
       "j       13      14      2\n",
       "c        9       2     23\n",
       "f       15      26      9"
      ]
     },
     "execution_count": 234,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis = 1,ascending=False) #按列名排序，降序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "id": "a3113a75",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>15</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>17</td>\n",
       "      <td>10</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>20</td>\n",
       "      <td>8</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>28</td>\n",
       "      <td>15</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "h       0      9       28\n",
       "r       1     24       12\n",
       "f       1      1       11\n",
       "g       1      4       14\n",
       "c       2     23        9\n",
       "u       4     24       20\n",
       "e       6     24        2\n",
       "c       9      7       26\n",
       "r      11      0       27\n",
       "j      12     19        9\n",
       "n      13     22        1\n",
       "t      13     12        3\n",
       "a      14     20       19\n",
       "j      14      2       13\n",
       "w      15     20        5\n",
       "v      16     26       23\n",
       "i      17     10       19\n",
       "h      20      8       11\n",
       "d      21     24       19\n",
       "y      22     27       19\n",
       "q      22     27        4\n",
       "c      23     29        0\n",
       "g      25     29        9\n",
       "o      26     27        1\n",
       "f      26      9       15\n",
       "f      27     12       12\n",
       "i      27      5        6\n",
       "s      28     23       20\n",
       "e      28     15       27\n",
       "b      28     10        9"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、属性值排序\n",
    "df.sort_values(by = ['Python']) #按Python属性值排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "id": "22cab490",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>12</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>15</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>17</td>\n",
       "      <td>10</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>20</td>\n",
       "      <td>8</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>28</td>\n",
       "      <td>15</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "h       0      9       28\n",
       "f       1      1       11\n",
       "g       1      4       14\n",
       "r       1     24       12\n",
       "c       2     23        9\n",
       "u       4     24       20\n",
       "e       6     24        2\n",
       "c       9      7       26\n",
       "r      11      0       27\n",
       "j      12     19        9\n",
       "t      13     12        3\n",
       "n      13     22        1\n",
       "j      14      2       13\n",
       "a      14     20       19\n",
       "w      15     20        5\n",
       "v      16     26       23\n",
       "i      17     10       19\n",
       "h      20      8       11\n",
       "d      21     24       19\n",
       "q      22     27        4\n",
       "y      22     27       19\n",
       "c      23     29        0\n",
       "g      25     29        9\n",
       "f      26      9       15\n",
       "o      26     27        1\n",
       "i      27      5        6\n",
       "f      27     12       12\n",
       "b      28     10        9\n",
       "e      28     15       27\n",
       "s      28     23       20"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by = ['Python','Keras'])#先按Python，再按Keras排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "id": "74c35f0b",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>25</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>23</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>22</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>26</td>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>16</td>\n",
       "      <td>26</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "g      25     29        9\n",
       "c      23     29        0\n",
       "q      22     27        4\n",
       "y      22     27       19\n",
       "o      26     27        1\n",
       "v      16     26       23\n",
       "r       1     24       12\n",
       "u       4     24       20\n",
       "d      21     24       19\n",
       "e       6     24        2"
      ]
     },
     "execution_count": 237,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、返回属性n大或者n小的值\n",
    "df.nlargest(10,columns='Keras') # 根据属性Keras排序,返回最大10个数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "id": "8c33490f",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Keras  Pytorch\n",
       "h       0      9       28\n",
       "r       1     24       12\n",
       "f       1      1       11\n",
       "g       1      4       14\n",
       "c       2     23        9"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.nsmallest(5,columns='Python') # 根据属性Python排序，返回最小5个数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "548bc243",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b8166ea",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "f14715d0",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# pandas分箱操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "id": "4dd6b0d2",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>137</td>\n",
       "      <td>4</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>46</td>\n",
       "      <td>78</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>61</td>\n",
       "      <td>112</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>124</td>\n",
       "      <td>5</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34</td>\n",
       "      <td>57</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>81</td>\n",
       "      <td>30</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>134</td>\n",
       "      <td>38</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>119</td>\n",
       "      <td>23</td>\n",
       "      <td>129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>61</td>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>64</td>\n",
       "      <td>33</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "0      137           4    136\n",
       "1       46          78      7\n",
       "2       61         112     51\n",
       "3      124           5     84\n",
       "4       34          57     92\n",
       "..     ...         ...    ...\n",
       "95      81          30     38\n",
       "96     134          38     47\n",
       "97     119          23    129\n",
       "98      61          35     45\n",
       "99      64          33     43\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 240,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = (100,3)),\n",
    "        columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "132a5e66",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      (99.333, 149.0]\n",
       "1     (-0.149, 49.667]\n",
       "2     (49.667, 99.333]\n",
       "3      (99.333, 149.0]\n",
       "4     (-0.149, 49.667]\n",
       "            ...       \n",
       "95    (49.667, 99.333]\n",
       "96     (99.333, 149.0]\n",
       "97     (99.333, 149.0]\n",
       "98    (49.667, 99.333]\n",
       "99    (49.667, 99.333]\n",
       "Name: Python, Length: 100, dtype: category\n",
       "Categories (3, interval[float64, right]): [(-0.149, 49.667] < (49.667, 99.333] < (99.333, 149.0]]"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、等宽分箱\n",
    "pd.cut(df.Python,bins = 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 242,
   "id": "a4fa7f65",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      优秀\n",
       "1     不及格\n",
       "2     不及格\n",
       "3      中等\n",
       "4      良好\n",
       "     ... \n",
       "95    不及格\n",
       "96    不及格\n",
       "97     优秀\n",
       "98    不及格\n",
       "99    不及格\n",
       "Name: Keras, Length: 100, dtype: category\n",
       "Categories (4, object): ['不及格' < '中等' < '良好' < '优秀']"
      ]
     },
     "execution_count": 242,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 指定宽度分箱\n",
    "pd.cut(df.Keras,#分箱数据\n",
    "    bins = [0,60,90,120,150],#分箱断点\n",
    "    right = False,# 左闭右开\n",
    "    labels=['不及格','中等','良好','优秀'])# 分箱后分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "id": "c67be053",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     优\n",
       "1     中\n",
       "2     中\n",
       "3     优\n",
       "4     差\n",
       "     ..\n",
       "95    良\n",
       "96    优\n",
       "97    优\n",
       "98    中\n",
       "99    中\n",
       "Name: Python, Length: 100, dtype: category\n",
       "Categories (4, object): ['差' < '中' < '良' < '优']"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、等频分箱\n",
    "pd.qcut(df.Python,q = 4,# 4等分\n",
    "        labels=['差','中','良','优']) # 分箱后分类\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e31bd50d",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4d21e0db",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "# pandas分组聚合"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ab34eb6",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## 分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "id": "b764723d",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>141</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>70</td>\n",
       "      <td>25</td>\n",
       "      <td>140</td>\n",
       "      <td>146</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>58</td>\n",
       "      <td>89</td>\n",
       "      <td>149</td>\n",
       "      <td>58</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>45</td>\n",
       "      <td>65</td>\n",
       "      <td>60</td>\n",
       "      <td>73</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>106</td>\n",
       "      <td>96</td>\n",
       "      <td>14</td>\n",
       "      <td>125</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>85</td>\n",
       "      <td>126</td>\n",
       "      <td>134</td>\n",
       "      <td>137</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "      <td>83</td>\n",
       "      <td>88</td>\n",
       "      <td>126</td>\n",
       "      <td>38</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>90</td>\n",
       "      <td>22</td>\n",
       "      <td>128</td>\n",
       "      <td>74</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>138</td>\n",
       "      <td>70</td>\n",
       "      <td>103</td>\n",
       "      <td>68</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>10</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "      <td>64</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     sex  class  Python  Keras  Tensorflow  Java  C++\n",
       "0      0      2      14    141          31    56  134\n",
       "1      1      6      70     25         140   146   10\n",
       "2      1      5      58     89         149    58  124\n",
       "3      0      7      45     65          60    73   53\n",
       "4      0      1     106     96          14   125   21\n",
       "..   ...    ...     ...    ...         ...   ...  ...\n",
       "295    0      7      85    126         134   137  104\n",
       "296    1      8      83     88         126    38   38\n",
       "297    1      4      90     22         128    74    9\n",
       "298    1      4     138     70         103    68   97\n",
       "299    0      2      10     53          61    64  147\n",
       "\n",
       "[300 rows x 7 columns]"
      ]
     },
     "execution_count": 247,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 准备数据\n",
    "df = pd.DataFrame(data = {'sex':np.random.randint(0,2,size = 300), # 0男，1女\n",
    "        'class':np.random.randint(1,9,size = 300),#1~8八个班\n",
    "        'Python':np.random.randint(0,151,size = 300),#Python成绩\n",
    "        'Keras':np.random.randint(0,151,size =300),#Keras成绩\n",
    "        'Tensorflow':np.random.randint(0,151,size=300),\n",
    "        'Java':np.random.randint(0,151,size = 300),\n",
    "        'C++':np.random.randint(0,151,size = 300)})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 248,
   "id": "2cb634ab",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>141</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>女</td>\n",
       "      <td>6</td>\n",
       "      <td>70</td>\n",
       "      <td>25</td>\n",
       "      <td>140</td>\n",
       "      <td>146</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>女</td>\n",
       "      <td>5</td>\n",
       "      <td>58</td>\n",
       "      <td>89</td>\n",
       "      <td>149</td>\n",
       "      <td>58</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>45</td>\n",
       "      <td>65</td>\n",
       "      <td>60</td>\n",
       "      <td>73</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>106</td>\n",
       "      <td>96</td>\n",
       "      <td>14</td>\n",
       "      <td>125</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>85</td>\n",
       "      <td>126</td>\n",
       "      <td>134</td>\n",
       "      <td>137</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>女</td>\n",
       "      <td>8</td>\n",
       "      <td>83</td>\n",
       "      <td>88</td>\n",
       "      <td>126</td>\n",
       "      <td>38</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>女</td>\n",
       "      <td>4</td>\n",
       "      <td>90</td>\n",
       "      <td>22</td>\n",
       "      <td>128</td>\n",
       "      <td>74</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>女</td>\n",
       "      <td>4</td>\n",
       "      <td>138</td>\n",
       "      <td>70</td>\n",
       "      <td>103</td>\n",
       "      <td>68</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>10</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "      <td>64</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    sex  class  Python  Keras  Tensorflow  Java  C++\n",
       "0     男      2      14    141          31    56  134\n",
       "1     女      6      70     25         140   146   10\n",
       "2     女      5      58     89         149    58  124\n",
       "3     男      7      45     65          60    73   53\n",
       "4     男      1     106     96          14   125   21\n",
       "..   ..    ...     ...    ...         ...   ...  ...\n",
       "295   男      7      85    126         134   137  104\n",
       "296   女      8      83     88         126    38   38\n",
       "297   女      4      90     22         128    74    9\n",
       "298   女      4     138     70         103    68   97\n",
       "299   男      2      10     53          61    64  147\n",
       "\n",
       "[300 rows x 7 columns]"
      ]
     },
     "execution_count": 248,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['sex'] = df['sex'].map({0:'男',1:'女'}) # 将0，1映射成男女\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "id": "67bab57a",
   "metadata": {
    "hidden": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "组名： 女\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "1     女      6      70     25         140   146   10\n",
      "2     女      5      58     89         149    58  124\n",
      "5     女      1      56    104          94    25   79\n",
      "6     女      2     124    133          97    44  135\n",
      "7     女      4      97      7         124   148   26\n",
      "..   ..    ...     ...    ...         ...   ...  ...\n",
      "291   女      7      14    138          16    89  145\n",
      "292   女      1      23    117          22    50   93\n",
      "296   女      8      83     88         126    38   38\n",
      "297   女      4      90     22         128    74    9\n",
      "298   女      4     138     70         103    68   97\n",
      "\n",
      "[151 rows x 7 columns]\n",
      "组名： 男\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "0     男      2      14    141          31    56  134\n",
      "3     男      7      45     65          60    73   53\n",
      "4     男      1     106     96          14   125   21\n",
      "10    男      6      12    134          26    80   68\n",
      "12    男      1      47    121         115    18    5\n",
      "..   ..    ...     ...    ...         ...   ...  ...\n",
      "290   男      7      67     97          75    81  149\n",
      "293   男      1      81      6         147    50   65\n",
      "294   男      5      94     35          27   113   46\n",
      "295   男      7      85    126         134   137  104\n",
      "299   男      2      10     53          61    64  147\n",
      "\n",
      "[149 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "# 1、分组->可迭代对象\n",
    "# 1.1 先分组再获取数据\n",
    "g = df.groupby(by = 'sex')[['Python','Java']] # 单分组\n",
    "for name,data in g:\n",
    "    print('组名：',name)\n",
    "    print('数据：',data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "id": "8ca3b055",
   "metadata": {
    "hidden": true,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.SeriesGroupBy object at 0x000001EFE6C38580>"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 准备数据\n",
    "df = pd.DataFrame(data = {'sex':np.random.randint(0,2,size = 300), # 0男，1女\n",
    "        'class':np.random.randint(1,9,size = 300),#1~8八个班\n",
    "        'Python':np.random.randint(0,151,size = 300),#Python成绩\n",
    "        'Keras':np.random.randint(0,151,size =300),#Keras成绩\n",
    "        'Tensorflow':np.random.randint(0,151,size=300),\n",
    "        'Java':np.random.randint(0,151,size = 300),\n",
    "        'C++':np.random.randint(0,151,size = 300)})\n",
    "df\n",
    "# 1.2 对一列值进行分组\n",
    "df['Python'].groupby(df['class']) # 单分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14fd2baf",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f216fbd",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed7f1981",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80df3dd6",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb5dd67d",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1b4376a1",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas分组聚合(apply,transform,agg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "734dd14f",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c02d295c",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3837c38",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "aeff9530",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas时间戳操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41b2f4e8",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bdcfe469",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas时间戳索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c544091",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d8b42307",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas时间序列常用操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bfcda738",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8f31c104",
   "metadata": {
    "hidden": true
   },
   "source": [
    "## pandas数据可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6fa149f",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4ddead6",
   "metadata": {
    "hidden": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b5a76cce",
   "metadata": {},
   "source": [
    "# pandas实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 316,
   "id": "8e99d847",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3683, 12)"
      ]
     },
     "execution_count": 316,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "job = pd.read_csv('./lagou2020.csv')\n",
    "job.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "id": "2ebbca7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>positionName</th>\n",
       "      <th>companyShortName</th>\n",
       "      <th>city</th>\n",
       "      <th>companySize</th>\n",
       "      <th>education</th>\n",
       "      <th>financeStage</th>\n",
       "      <th>industryField</th>\n",
       "      <th>salary</th>\n",
       "      <th>workYear</th>\n",
       "      <th>hitags</th>\n",
       "      <th>companyLabelList</th>\n",
       "      <th>job_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>拉勾网</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>本科</td>\n",
       "      <td>D轮及以上</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>25k-35k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>[\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...</td>\n",
       "      <td>[\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]</td>\n",
       "      <td>\\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>数据分析师</td>\n",
       "      <td>OK Group</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>B轮</td>\n",
       "      <td>金融</td>\n",
       "      <td>25k-45k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]</td>\n",
       "      <td>\\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>数据分析师</td>\n",
       "      <td>京东集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>电商</td>\n",
       "      <td>15k-30k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>[\"免费班车\",\"免费体检\",\"地铁周边\"]</td>\n",
       "      <td>[\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]</td>\n",
       "      <td>\\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  positionName companyShortName city companySize education financeStage  \\\n",
       "0      高级数据分析师              拉勾网   北京   500-2000人        本科        D轮及以上   \n",
       "1        数据分析师         OK Group   北京   500-2000人        大专           B轮   \n",
       "2      高级数据分析师           金山办公软件   北京     2000人以上        本科         上市公司   \n",
       "3        数据分析师           金山办公软件   北京     2000人以上        本科         上市公司   \n",
       "4        数据分析师             京东集团   北京     2000人以上        本科         上市公司   \n",
       "\n",
       "  industryField   salary workYear  \\\n",
       "0          企业服务  25k-35k    5-10年   \n",
       "1            金融  25k-45k    5-10年   \n",
       "2         移动互联网  15k-25k     3-5年   \n",
       "3         移动互联网  15k-25k     1-3年   \n",
       "4            电商  15k-30k     3-5年   \n",
       "\n",
       "                                              hitags  \\\n",
       "0  [\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...   \n",
       "1                                                NaN   \n",
       "2                                                NaN   \n",
       "3                                                NaN   \n",
       "4                             [\"免费班车\",\"免费体检\",\"地铁周边\"]   \n",
       "\n",
       "                companyLabelList  \\\n",
       "0  [\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]   \n",
       "1   [\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]   \n",
       "2  [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "3  [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "4  [\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]   \n",
       "\n",
       "                                          job_detail  \n",
       "0  \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...  \n",
       "1  \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...  \n",
       "2  \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...  \n",
       "3  \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...  \n",
       "4  \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...  "
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 306,
   "id": "03c3beba",
   "metadata": {},
   "outputs": [],
   "source": [
    "job.drop_duplicates(inplace = True) # 删除重复数据\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 307,
   "id": "68894270",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['北京', '上海', '深圳', '广州', '杭州', '成都', '南京', '武汉', '西安', '厦门', '长沙',\n",
       "       '苏州', '天津'], dtype=object)"
      ]
     },
     "execution_count": 307,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.city.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 308,
   "id": "cd912395",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3507, 12)"
      ]
     },
     "execution_count": 308,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 309,
   "id": "ecebeccd",
   "metadata": {},
   "outputs": [],
   "source": [
    "job.reset_index(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "id": "8662fde2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>positionName</th>\n",
       "      <th>companyShortName</th>\n",
       "      <th>city</th>\n",
       "      <th>companySize</th>\n",
       "      <th>education</th>\n",
       "      <th>financeStage</th>\n",
       "      <th>industryField</th>\n",
       "      <th>salary</th>\n",
       "      <th>workYear</th>\n",
       "      <th>hitags</th>\n",
       "      <th>companyLabelList</th>\n",
       "      <th>job_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>拉勾网</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>本科</td>\n",
       "      <td>D轮及以上</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>25k-35k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>[\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...</td>\n",
       "      <td>[\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]</td>\n",
       "      <td>\\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>OK Group</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>B轮</td>\n",
       "      <td>金融</td>\n",
       "      <td>25k-45k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]</td>\n",
       "      <td>\\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>京东集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>电商</td>\n",
       "      <td>15k-30k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>[\"免费班车\",\"免费体检\",\"地铁周边\"]</td>\n",
       "      <td>[\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]</td>\n",
       "      <td>\\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3502</th>\n",
       "      <td>3678</td>\n",
       "      <td>内容运营高级经理-审核方向</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>20k-30k</td>\n",
       "      <td>不限</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、负责字节跳动旗下产品图文类及小视频类内容的业务管理，对...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3503</th>\n",
       "      <td>3679</td>\n",
       "      <td>质检岗位基层管理岗</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>6k-10k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、负责对日常业务数据进行分析、挖掘潜在隐患风险、提出风险...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3504</th>\n",
       "      <td>3680</td>\n",
       "      <td>高级审核编辑</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>8k-12k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、根据审核标准，对自媒体发布的国内热点、新闻、优质内容做...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3505</th>\n",
       "      <td>3681</td>\n",
       "      <td>数据运营分析专员</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>6k-8k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3506</th>\n",
       "      <td>3682</td>\n",
       "      <td>数据运营分析实习生</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>2k-3k</td>\n",
       "      <td>不限</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3507 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      index   positionName companyShortName city companySize education  \\\n",
       "0         0        高级数据分析师              拉勾网   北京   500-2000人        本科   \n",
       "1         1          数据分析师         OK Group   北京   500-2000人        大专   \n",
       "2         2        高级数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "3         3          数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "4         4          数据分析师             京东集团   北京     2000人以上        本科   \n",
       "...     ...            ...              ...  ...         ...       ...   \n",
       "3502   3678  内容运营高级经理-审核方向             字节跳动   天津     2000人以上        本科   \n",
       "3503   3679      质检岗位基层管理岗             字节跳动   天津     2000人以上        本科   \n",
       "3504   3680         高级审核编辑             字节跳动   天津     2000人以上        本科   \n",
       "3505   3681       数据运营分析专员             字节跳动   天津     2000人以上        本科   \n",
       "3506   3682      数据运营分析实习生             字节跳动   天津     2000人以上        本科   \n",
       "\n",
       "     financeStage industryField   salary workYear  \\\n",
       "0           D轮及以上          企业服务  25k-35k    5-10年   \n",
       "1              B轮            金融  25k-45k    5-10年   \n",
       "2            上市公司         移动互联网  15k-25k     3-5年   \n",
       "3            上市公司         移动互联网  15k-25k     1-3年   \n",
       "4            上市公司            电商  15k-30k     3-5年   \n",
       "...           ...           ...      ...      ...   \n",
       "3502           C轮         文娱丨内容  20k-30k       不限   \n",
       "3503           C轮         文娱丨内容   6k-10k     3-5年   \n",
       "3504           C轮         文娱丨内容   8k-12k     3-5年   \n",
       "3505           C轮         文娱丨内容    6k-8k     3-5年   \n",
       "3506           C轮         文娱丨内容    2k-3k       不限   \n",
       "\n",
       "                                                 hitags  \\\n",
       "0     [\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...   \n",
       "1                                                   NaN   \n",
       "2                                                   NaN   \n",
       "3                                                   NaN   \n",
       "4                                [\"免费班车\",\"免费体检\",\"地铁周边\"]   \n",
       "...                                                 ...   \n",
       "3502                                                NaN   \n",
       "3503                                                NaN   \n",
       "3504                                                NaN   \n",
       "3505                                                NaN   \n",
       "3506                                                NaN   \n",
       "\n",
       "                       companyLabelList  \\\n",
       "0         [\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]   \n",
       "1          [\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]   \n",
       "2         [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "3         [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "4         [\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]   \n",
       "...                                 ...   \n",
       "3502  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3503  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3504  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3505  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3506  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "\n",
       "                                             job_detail  \n",
       "0     \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...  \n",
       "1     \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...  \n",
       "2     \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...  \n",
       "3     \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...  \n",
       "4     \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...  \n",
       "...                                                 ...  \n",
       "3502  \\n        职位职责：\\n1、负责字节跳动旗下产品图文类及小视频类内容的业务管理，对...  \n",
       "3503  \\n        职位职责：\\n1、负责对日常业务数据进行分析、挖掘潜在隐患风险、提出风险...  \n",
       "3504  \\n        职位职责：\\n1、根据审核标准，对自媒体发布的国内热点、新闻、优质内容做...  \n",
       "3505  \\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...  \n",
       "3506  \\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...  \n",
       "\n",
       "[3507 rows x 13 columns]"
      ]
     },
     "execution_count": 310,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bdc95843",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b3db26fb",
   "metadata": {},
   "source": [
    "## 过滤非数据分析的岗位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "id": "fa79e56a",
   "metadata": {},
   "outputs": [],
   "source": [
    "con = job['positionName'].str.contains('数据分析')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "id": "3029f7f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1652, 13)"
      ]
     },
     "execution_count": 312,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = job[con]\n",
    "job.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "id": "44dceed3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>positionName</th>\n",
       "      <th>companyShortName</th>\n",
       "      <th>city</th>\n",
       "      <th>companySize</th>\n",
       "      <th>education</th>\n",
       "      <th>financeStage</th>\n",
       "      <th>industryField</th>\n",
       "      <th>salary</th>\n",
       "      <th>workYear</th>\n",
       "      <th>hitags</th>\n",
       "      <th>companyLabelList</th>\n",
       "      <th>job_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>拉勾网</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>本科</td>\n",
       "      <td>D轮及以上</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>25k-35k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>[\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...</td>\n",
       "      <td>[\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]</td>\n",
       "      <td>\\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>OK Group</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>B轮</td>\n",
       "      <td>金融</td>\n",
       "      <td>25k-45k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]</td>\n",
       "      <td>\\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>京东集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>电商</td>\n",
       "      <td>15k-30k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>[\"免费班车\",\"免费体检\",\"地铁周边\"]</td>\n",
       "      <td>[\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]</td>\n",
       "      <td>\\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3177</th>\n",
       "      <td>3352</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>华泛信息</td>\n",
       "      <td>苏州</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>大专</td>\n",
       "      <td>不需要融资</td>\n",
       "      <td>移动互联网,其他</td>\n",
       "      <td>10k-15k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"技能培训\",\"节日礼物\",\"带薪年假\",\"绩效奖金\"]</td>\n",
       "      <td>\\n岗位职责：\\n深入了解项目组的业务需求,在此基础上进行数据收集、数据分析、商业报告的撰写...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3178</th>\n",
       "      <td>3353</td>\n",
       "      <td>大数据分析师</td>\n",
       "      <td>德融嘉信</td>\n",
       "      <td>苏州</td>\n",
       "      <td>50-150人</td>\n",
       "      <td>本科</td>\n",
       "      <td>不需要融资</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>6k-12k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[]</td>\n",
       "      <td>\\n岗位职责：\\n1. 开展业务专题分析，使用数据挖掘各类算法构建相关的业务模型，完成业务分...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3404</th>\n",
       "      <td>3580</td>\n",
       "      <td>ETL/大数据/数据分析/实施</td>\n",
       "      <td>格蒂电力</td>\n",
       "      <td>天津</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>未融资</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>6k-12k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"技能培训\",\"带薪年假\",\"绩效奖金\",\"岗位晋升\"]</td>\n",
       "      <td>\\n工作职责\\n1.   负责数据接入、数据整合中的链路配置与调度配置工作。\\n职位要求\\n...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3405</th>\n",
       "      <td>3581</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>吉城美家</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>未融资</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>7k-14k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"五险一金\",\"岗位晋升\"]</td>\n",
       "      <td>\\n负责站点日常数据分析、提前通过数据分析对业务有预测性、通过数据说话、解决站点管理问题、\\n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3406</th>\n",
       "      <td>3582</td>\n",
       "      <td>数据分析支持</td>\n",
       "      <td>云链供应链</td>\n",
       "      <td>天津</td>\n",
       "      <td>15-50人</td>\n",
       "      <td>本科</td>\n",
       "      <td>未融资</td>\n",
       "      <td>金融,企业服务</td>\n",
       "      <td>4k-6k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[]</td>\n",
       "      <td>\\n        岗位职责：\\n1、负责部门日常数据报表的制定、维护、优化；\\n2、支持运...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1652 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      index     positionName companyShortName city companySize education  \\\n",
       "0         0          高级数据分析师              拉勾网   北京   500-2000人        本科   \n",
       "1         1            数据分析师         OK Group   北京   500-2000人        大专   \n",
       "2         2          高级数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "3         3            数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "4         4            数据分析师             京东集团   北京     2000人以上        本科   \n",
       "...     ...              ...              ...  ...         ...       ...   \n",
       "3177   3352            数据分析师             华泛信息   苏州     2000人以上        大专   \n",
       "3178   3353           大数据分析师             德融嘉信   苏州     50-150人        本科   \n",
       "3404   3580  ETL/大数据/数据分析/实施             格蒂电力   天津   500-2000人        大专   \n",
       "3405   3581            数据分析师             吉城美家   天津     2000人以上        本科   \n",
       "3406   3582           数据分析支持            云链供应链   天津      15-50人        本科   \n",
       "\n",
       "     financeStage industryField   salary workYear  \\\n",
       "0           D轮及以上          企业服务  25k-35k    5-10年   \n",
       "1              B轮            金融  25k-45k    5-10年   \n",
       "2            上市公司         移动互联网  15k-25k     3-5年   \n",
       "3            上市公司         移动互联网  15k-25k     1-3年   \n",
       "4            上市公司            电商  15k-30k     3-5年   \n",
       "...           ...           ...      ...      ...   \n",
       "3177        不需要融资      移动互联网,其他  10k-15k     1-3年   \n",
       "3178        不需要融资         移动互联网   6k-12k     1-3年   \n",
       "3404          未融资          企业服务   6k-12k     3-5年   \n",
       "3405          未融资         移动互联网   7k-14k     1-3年   \n",
       "3406          未融资       金融,企业服务    4k-6k     1-3年   \n",
       "\n",
       "                                                 hitags  \\\n",
       "0     [\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...   \n",
       "1                                                   NaN   \n",
       "2                                                   NaN   \n",
       "3                                                   NaN   \n",
       "4                                [\"免费班车\",\"免费体检\",\"地铁周边\"]   \n",
       "...                                                 ...   \n",
       "3177                                                NaN   \n",
       "3178                                                NaN   \n",
       "3404                                                NaN   \n",
       "3405                                                NaN   \n",
       "3406                                                NaN   \n",
       "\n",
       "                   companyLabelList  \\\n",
       "0     [\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]   \n",
       "1      [\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]   \n",
       "2     [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "3     [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "4     [\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]   \n",
       "...                             ...   \n",
       "3177  [\"技能培训\",\"节日礼物\",\"带薪年假\",\"绩效奖金\"]   \n",
       "3178                             []   \n",
       "3404  [\"技能培训\",\"带薪年假\",\"绩效奖金\",\"岗位晋升\"]   \n",
       "3405                [\"五险一金\",\"岗位晋升\"]   \n",
       "3406                             []   \n",
       "\n",
       "                                             job_detail  \n",
       "0     \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...  \n",
       "1     \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...  \n",
       "2     \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...  \n",
       "3     \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...  \n",
       "4     \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...  \n",
       "...                                                 ...  \n",
       "3177  \\n岗位职责：\\n深入了解项目组的业务需求,在此基础上进行数据收集、数据分析、商业报告的撰写...  \n",
       "3178  \\n岗位职责：\\n1. 开展业务专题分析，使用数据挖掘各类算法构建相关的业务模型，完成业务分...  \n",
       "3404  \\n工作职责\\n1.   负责数据接入、数据整合中的链路配置与调度配置工作。\\n职位要求\\n...  \n",
       "3405    \\n负责站点日常数据分析、提前通过数据分析对业务有预测性、通过数据说话、解决站点管理问题、\\n  \n",
       "3406  \\n        岗位职责：\\n1、负责部门日常数据报表的制定、维护、优化；\\n2、支持运...  \n",
       "\n",
       "[1652 rows x 13 columns]"
      ]
     },
     "execution_count": 270,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 317,
   "id": "c7aeda0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>positionName</th>\n",
       "      <th>companyShortName</th>\n",
       "      <th>city</th>\n",
       "      <th>companySize</th>\n",
       "      <th>education</th>\n",
       "      <th>financeStage</th>\n",
       "      <th>industryField</th>\n",
       "      <th>salary</th>\n",
       "      <th>workYear</th>\n",
       "      <th>hitags</th>\n",
       "      <th>companyLabelList</th>\n",
       "      <th>job_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>拉勾网</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>本科</td>\n",
       "      <td>D轮及以上</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>25k-35k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>[\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...</td>\n",
       "      <td>[\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]</td>\n",
       "      <td>\\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>OK Group</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>B轮</td>\n",
       "      <td>金融</td>\n",
       "      <td>25k-45k</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]</td>\n",
       "      <td>\\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>15k-25k</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>京东集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>电商</td>\n",
       "      <td>15k-30k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>[\"免费班车\",\"免费体检\",\"地铁周边\"]</td>\n",
       "      <td>[\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]</td>\n",
       "      <td>\\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3678</th>\n",
       "      <td>3678</td>\n",
       "      <td>内容运营高级经理-审核方向</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>20k-30k</td>\n",
       "      <td>不限</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、负责字节跳动旗下产品图文类及小视频类内容的业务管理，对...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3679</th>\n",
       "      <td>3679</td>\n",
       "      <td>质检岗位基层管理岗</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>6k-10k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、负责对日常业务数据进行分析、挖掘潜在隐患风险、提出风险...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3680</th>\n",
       "      <td>3680</td>\n",
       "      <td>高级审核编辑</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>8k-12k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、根据审核标准，对自媒体发布的国内热点、新闻、优质内容做...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3681</th>\n",
       "      <td>3681</td>\n",
       "      <td>数据运营分析专员</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>6k-8k</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3682</th>\n",
       "      <td>3682</td>\n",
       "      <td>数据运营分析实习生</td>\n",
       "      <td>字节跳动</td>\n",
       "      <td>天津</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>C轮</td>\n",
       "      <td>文娱丨内容</td>\n",
       "      <td>2k-3k</td>\n",
       "      <td>不限</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]</td>\n",
       "      <td>\\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3683 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      index   positionName companyShortName city companySize education  \\\n",
       "0         0        高级数据分析师              拉勾网   北京   500-2000人        本科   \n",
       "1         1          数据分析师         OK Group   北京   500-2000人        大专   \n",
       "2         2        高级数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "3         3          数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "4         4          数据分析师             京东集团   北京     2000人以上        本科   \n",
       "...     ...            ...              ...  ...         ...       ...   \n",
       "3678   3678  内容运营高级经理-审核方向             字节跳动   天津     2000人以上        本科   \n",
       "3679   3679      质检岗位基层管理岗             字节跳动   天津     2000人以上        本科   \n",
       "3680   3680         高级审核编辑             字节跳动   天津     2000人以上        本科   \n",
       "3681   3681       数据运营分析专员             字节跳动   天津     2000人以上        本科   \n",
       "3682   3682      数据运营分析实习生             字节跳动   天津     2000人以上        本科   \n",
       "\n",
       "     financeStage industryField   salary workYear  \\\n",
       "0           D轮及以上          企业服务  25k-35k    5-10年   \n",
       "1              B轮            金融  25k-45k    5-10年   \n",
       "2            上市公司         移动互联网  15k-25k     3-5年   \n",
       "3            上市公司         移动互联网  15k-25k     1-3年   \n",
       "4            上市公司            电商  15k-30k     3-5年   \n",
       "...           ...           ...      ...      ...   \n",
       "3678           C轮         文娱丨内容  20k-30k       不限   \n",
       "3679           C轮         文娱丨内容   6k-10k     3-5年   \n",
       "3680           C轮         文娱丨内容   8k-12k     3-5年   \n",
       "3681           C轮         文娱丨内容    6k-8k     3-5年   \n",
       "3682           C轮         文娱丨内容    2k-3k       不限   \n",
       "\n",
       "                                                 hitags  \\\n",
       "0     [\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...   \n",
       "1                                                   NaN   \n",
       "2                                                   NaN   \n",
       "3                                                   NaN   \n",
       "4                                [\"免费班车\",\"免费体检\",\"地铁周边\"]   \n",
       "...                                                 ...   \n",
       "3678                                                NaN   \n",
       "3679                                                NaN   \n",
       "3680                                                NaN   \n",
       "3681                                                NaN   \n",
       "3682                                                NaN   \n",
       "\n",
       "                       companyLabelList  \\\n",
       "0         [\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]   \n",
       "1          [\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]   \n",
       "2         [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "3         [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "4         [\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]   \n",
       "...                                 ...   \n",
       "3678  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3679  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3680  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3681  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "3682  [\"扁平管理\",\"弹性工作\",\"大厨定制三餐\",\"就近租房补贴\"]   \n",
       "\n",
       "                                             job_detail  \n",
       "0     \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...  \n",
       "1     \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...  \n",
       "2     \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...  \n",
       "3     \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...  \n",
       "4     \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...  \n",
       "...                                                 ...  \n",
       "3678  \\n        职位职责：\\n1、负责字节跳动旗下产品图文类及小视频类内容的业务管理，对...  \n",
       "3679  \\n        职位职责：\\n1、负责对日常业务数据进行分析、挖掘潜在隐患风险、提出风险...  \n",
       "3680  \\n        职位职责：\\n1、根据审核标准，对自媒体发布的国内热点、新闻、优质内容做...  \n",
       "3681  \\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...  \n",
       "3682  \\n        职位职责：\\n1、协助数据分析团队项目的测试及开展，了解公司各部门的组织...  \n",
       "\n",
       "[3683 rows x 13 columns]"
      ]
     },
     "execution_count": 317,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.reset_index(inplace=True)\n",
    "job"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b9eafd8",
   "metadata": {},
   "source": [
    "## 薪水"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 318,
   "id": "cdb35591",
   "metadata": {},
   "outputs": [],
   "source": [
    "# applymap 和map类似，map操作Series，applymap操作DataFrame\n",
    "job['salary'] = job['salary'].str.lower().str.extract(r'(\\d+)[k]-(\\d+)[k]').applymap(lambda x:int(x))\\\n",
    "             .mean(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fea580d2",
   "metadata": {},
   "source": [
    "## 技能要求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40450a02",
   "metadata": {},
   "outputs": [],
   "source": [
    "Python\n",
    "SQL\n",
    "Tableau\n",
    "Excel\n",
    "SPSS/SAS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 282,
   "id": "2b81182d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...\n",
       "1       \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...\n",
       "2       \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...\n",
       "3       \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...\n",
       "4       \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...\n",
       "                              ...                        \n",
       "1647    \\n岗位职责：\\n深入了解项目组的业务需求,在此基础上进行数据收集、数据分析、商业报告的撰写...\n",
       "1648    \\n岗位职责：\\n1. 开展业务专题分析，使用数据挖掘各类算法构建相关的业务模型，完成业务分...\n",
       "1649    \\n工作职责\\n1.   负责数据接入、数据整合中的链路配置与调度配置工作。\\n职位要求\\n...\n",
       "1650      \\n负责站点日常数据分析、提前通过数据分析对业务有预测性、通过数据说话、解决站点管理问题、\\n\n",
       "1651    \\n        岗位职责：\\n1、负责部门日常数据报表的制定、维护、优化；\\n2、支持运...\n",
       "Name: job_detail, Length: 1652, dtype: object"
      ]
     },
     "execution_count": 282,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " job['job_detail'].str.lower() #变成小写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "id": "53bfe814",
   "metadata": {},
   "outputs": [],
   "source": [
    "# job[\"Python\"] = job['job_detail'].map(lambda x: 1 if ('Python' in x) else 0)\n",
    "job[\"Python\"] = job[\"job_detail\"].map(lambda x:1 if ('python' in x) else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 323,
   "id": "82012c27",
   "metadata": {},
   "outputs": [],
   "source": [
    "job['SQL']=job['job_detail'].map(lambda x:1 if 'sql' in x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 320,
   "id": "434379a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "job['Tableau'] = job['job_detail'].map(lambda x:1 if 'tableau' in x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 321,
   "id": "d87ec9ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "job['Excel'] = job['job_detail'].map(lambda x:1 if 'excel' in x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 322,
   "id": "169cdeb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "job['SPSS/SAS'] = job['job_detail'].map(lambda x:1 if 'spss' in x or 'sas' in x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "id": "d82bd8f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>positionName</th>\n",
       "      <th>companyShortName</th>\n",
       "      <th>city</th>\n",
       "      <th>companySize</th>\n",
       "      <th>education</th>\n",
       "      <th>financeStage</th>\n",
       "      <th>industryField</th>\n",
       "      <th>salary</th>\n",
       "      <th>workYear</th>\n",
       "      <th>hitags</th>\n",
       "      <th>companyLabelList</th>\n",
       "      <th>job_detail</th>\n",
       "      <th>Python</th>\n",
       "      <th>Tableau</th>\n",
       "      <th>Excel</th>\n",
       "      <th>SPSS/SAS</th>\n",
       "      <th>SQL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>拉勾网</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>本科</td>\n",
       "      <td>D轮及以上</td>\n",
       "      <td>企业服务</td>\n",
       "      <td>30.0</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>[\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...</td>\n",
       "      <td>[\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]</td>\n",
       "      <td>\\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>OK Group</td>\n",
       "      <td>北京</td>\n",
       "      <td>500-2000人</td>\n",
       "      <td>大专</td>\n",
       "      <td>B轮</td>\n",
       "      <td>金融</td>\n",
       "      <td>35.0</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]</td>\n",
       "      <td>\\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>高级数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>20.0</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>金山办公软件</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>移动互联网</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]</td>\n",
       "      <td>\\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>数据分析师</td>\n",
       "      <td>京东集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>2000人以上</td>\n",
       "      <td>本科</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>电商</td>\n",
       "      <td>22.5</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>[\"免费班车\",\"免费体检\",\"地铁周边\"]</td>\n",
       "      <td>[\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]</td>\n",
       "      <td>\\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index positionName companyShortName city companySize education  \\\n",
       "0      0      高级数据分析师              拉勾网   北京   500-2000人        本科   \n",
       "1      1        数据分析师         OK Group   北京   500-2000人        大专   \n",
       "2      2      高级数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "3      3        数据分析师           金山办公软件   北京     2000人以上        本科   \n",
       "4      4        数据分析师             京东集团   北京     2000人以上        本科   \n",
       "\n",
       "  financeStage industryField  salary workYear  \\\n",
       "0        D轮及以上          企业服务    30.0    5-10年   \n",
       "1           B轮            金融    35.0    5-10年   \n",
       "2         上市公司         移动互联网    20.0     3-5年   \n",
       "3         上市公司         移动互联网    20.0     1-3年   \n",
       "4         上市公司            电商    22.5     3-5年   \n",
       "\n",
       "                                              hitags  \\\n",
       "0  [\"免费下午茶\",\"ipo倒计时\",\"bat背景\",\"地铁周边\",\"每天管两餐\",\"定期团建...   \n",
       "1                                                NaN   \n",
       "2                                                NaN   \n",
       "3                                                NaN   \n",
       "4                             [\"免费班车\",\"免费体检\",\"地铁周边\"]   \n",
       "\n",
       "                companyLabelList  \\\n",
       "0  [\"五险一金\",\"弹性工作\",\"带薪年假\",\"免费两餐\"]   \n",
       "1   [\"节日礼物\",\"年度旅游\",\"扁平管理\",\"领导好\"]   \n",
       "2  [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "3  [\"年底双薪\",\"节日礼物\",\"技能培训\",\"绩效奖金\"]   \n",
       "4  [\"五险一金\",\"带薪年假\",\"免费班车\",\"定期体检\"]   \n",
       "\n",
       "                                          job_detail  Python  Tableau  Excel  \\\n",
       "0  \\n1.搭建数据指标框架，完整并准确反映业务趋势和变化，及时发现和定位问题\\n2.独立完成数...       0        0      0   \n",
       "1  \\n工作职责：\\n1. 负责建立交易平台日常分析体系，包括核心指标体系、报表体系，专题活动分...       0        0      0   \n",
       "2  \\n职位描述：1.对亿计的办公用户数据进行深度挖掘，引导产品、运营，并能实际应用到业务中带来...       0        0      0   \n",
       "3  \\n工作职责：-负责日常运营、业务数据等分析-针对产品需求做深入的数据分析报告，分析用户行为...       0        0      0   \n",
       "4  \\n【数据分析师岗】\\n岗位要求：\\n1、构建及维护客户体验相关数据报表平台；\\n2、与大数...       0        0      1   \n",
       "\n",
       "   SPSS/SAS  SQL  \n",
       "0         0    0  \n",
       "1         0    0  \n",
       "2         0    0  \n",
       "3         1    0  \n",
       "4         0    0  "
      ]
     },
     "execution_count": 337,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c69f0628",
   "metadata": {},
   "source": [
    "## 行业信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 343,
   "id": "d1b8e3d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0           企业服务\n",
       "1             金融\n",
       "2          移动互联网\n",
       "3          移动互联网\n",
       "4             电商\n",
       "5             教育\n",
       "6             金融\n",
       "7          移动互联网\n",
       "8     移动互联网,消费生活\n",
       "9          移动互联网\n",
       "10      移动互联网,电商\n",
       "11       游戏,数据服务\n",
       "12      移动互联网,电商\n",
       "13      移动互联网,电商\n",
       "14          消费生活\n",
       "15         移动互联网\n",
       "16         移动互联网\n",
       "17      移动互联网,金融\n",
       "18            硬件\n",
       "19    移动互联网,消费生活\n",
       "20         移动互联网\n",
       "21            教育\n",
       "22    移动互联网,数据服务\n",
       "23      移动互联网,教育\n",
       "24         文娱丨内容\n",
       "25         移动互联网\n",
       "26      移动互联网,教育\n",
       "27    移动互联网,数据服务\n",
       "28      移动互联网,电商\n",
       "29      移动互联网,社交\n",
       "Name: industryField, dtype: object"
      ]
     },
     "execution_count": 343,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job['industryField'][:30]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 342,
   "id": "52e1e304",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        企业服务\n",
       "1          金融\n",
       "2       移动互联网\n",
       "3       移动互联网\n",
       "4          电商\n",
       "        ...  \n",
       "3678    文娱丨内容\n",
       "3679    文娱丨内容\n",
       "3680    文娱丨内容\n",
       "3681    文娱丨内容\n",
       "3682    文娱丨内容\n",
       "Name: industryField, Length: 3683, dtype: object"
      ]
     },
     "execution_count": 342,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job.industryField"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 347,
   "id": "ab3f0cac",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (Temp/ipykernel_20936/3082418870.py, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\lenovo\\AppData\\Local\\Temp/ipykernel_20936/3082418870.py\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m    if x[0] == \"移动互联网\" and len(x)>1:\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "def clean_industry(x):\n",
    "    x = x.split(\",\")\n",
    "        if x[0] == \"移动互联网\" and len(x)>1:\n",
    "    return x[1]\n",
    "        else:\n",
    "    return x[0]\n",
    "job[\"industryField\"] = job.industryField.map(clean_industry)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59416cc6",
   "metadata": {},
   "source": [
    "# 作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2ebc3372",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "58e0de13",
   "metadata": {},
   "outputs": [],
   "source": [
    "male = pd.read_excel('./18级高一体测成绩汇总.xls') #默认加载第一个工作表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8fabc253",
   "metadata": {},
   "outputs": [],
   "source": [
    "female = pd.read_excel('./18级高一体测成绩汇总.xls',sheet_name = 1) #指定加载第二个工作表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5ebe2f34",
   "metadata": {},
   "outputs": [],
   "source": [
    "rule = pd.read_excel('./体侧成绩评分表.xls',header = [0,1]) #评分标准加载,header=[0,1] 表示多层列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "41f4baf0",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "Can only use .str accessor with string values!",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_34744/4089700377.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmale\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'男1000米跑'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmale\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'男1000米跑'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreplace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"'\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\".\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mmale\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'男1000米跑'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_numeric\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmale\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'男1000米跑'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'coerce'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfillna\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lenovo\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m   5485\u001b[0m         ):\n\u001b[0;32m   5486\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 5487\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   5488\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5489\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lenovo\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\pandas\\core\\accessor.py\u001b[0m in \u001b[0;36m__get__\u001b[1;34m(self, obj, cls)\u001b[0m\n\u001b[0;32m    179\u001b[0m             \u001b[1;31m# we're accessing the attribute of the class, i.e., Dataset.geo\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    180\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_accessor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 181\u001b[1;33m         \u001b[0maccessor_obj\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_accessor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    182\u001b[0m         \u001b[1;31m# Replace the property with the accessor object. Inspired by:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    183\u001b[0m         \u001b[1;31m# https://www.pydanny.com/cached-property.html\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lenovo\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\pandas\\core\\strings\\accessor.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, data)\u001b[0m\n\u001b[0;32m    166\u001b[0m         \u001b[1;32mfrom\u001b[0m \u001b[0mpandas\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marrays\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstring_\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mStringDtype\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    167\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 168\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_inferred_dtype\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    169\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_categorical\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mis_categorical_dtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    170\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_string\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mStringDtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lenovo\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\pandas\\core\\strings\\accessor.py\u001b[0m in \u001b[0;36m_validate\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m    223\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    224\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0minferred_dtype\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mallowed_types\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 225\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Can only use .str accessor with string values!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    226\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0minferred_dtype\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    227\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: Can only use .str accessor with string values!"
     ]
    }
   ],
   "source": [
    "male['男1000米跑'] = male['男1000米跑'].str.replace(\"'\",\".\")\n",
    "male['男1000米跑'] = pd.to_numeric(male['男1000米跑'], errors='coerce').fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c8fa892a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>班级</th>\n",
       "      <th>性别</th>\n",
       "      <th>男1000米跑</th>\n",
       "      <th>男50米跑</th>\n",
       "      <th>男跳远</th>\n",
       "      <th>男体前屈</th>\n",
       "      <th>男引体</th>\n",
       "      <th>男肺活量</th>\n",
       "      <th>身高</th>\n",
       "      <th>体重</th>\n",
       "      <th>BMI</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>4.13</td>\n",
       "      <td>8.88</td>\n",
       "      <td>195.0</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>2785</td>\n",
       "      <td>170.0</td>\n",
       "      <td>72.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>4.16</td>\n",
       "      <td>7.70</td>\n",
       "      <td>225.0</td>\n",
       "      <td>11</td>\n",
       "      <td>7</td>\n",
       "      <td>3133</td>\n",
       "      <td>174.0</td>\n",
       "      <td>52.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>4.09</td>\n",
       "      <td>8.45</td>\n",
       "      <td>218.0</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>3901</td>\n",
       "      <td>169.0</td>\n",
       "      <td>46.5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>4.21</td>\n",
       "      <td>8.05</td>\n",
       "      <td>206.0</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>4946</td>\n",
       "      <td>183.0</td>\n",
       "      <td>79.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>3.44</td>\n",
       "      <td>7.52</td>\n",
       "      <td>210.0</td>\n",
       "      <td>13</td>\n",
       "      <td>9</td>\n",
       "      <td>3538</td>\n",
       "      <td>171.0</td>\n",
       "      <td>54.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>472</th>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "      <td>4.23</td>\n",
       "      <td>8.27</td>\n",
       "      <td>208.0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>4647</td>\n",
       "      <td>176.0</td>\n",
       "      <td>69.5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "      <td>5.19</td>\n",
       "      <td>9.55</td>\n",
       "      <td>210.0</td>\n",
       "      <td>15</td>\n",
       "      <td>6</td>\n",
       "      <td>7042</td>\n",
       "      <td>177.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>474</th>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "      <td>3.25</td>\n",
       "      <td>7.50</td>\n",
       "      <td>252.0</td>\n",
       "      <td>13</td>\n",
       "      <td>13</td>\n",
       "      <td>5755</td>\n",
       "      <td>181.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>475</th>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "      <td>4.39</td>\n",
       "      <td>7.81</td>\n",
       "      <td>208.0</td>\n",
       "      <td>14</td>\n",
       "      <td>11</td>\n",
       "      <td>5688</td>\n",
       "      <td>172.0</td>\n",
       "      <td>51.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>476</th>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>477 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     班级 性别  男1000米跑  男50米跑    男跳远  男体前屈  男引体  男肺活量     身高    体重  BMI\n",
       "0     1  男     4.13   8.88  195.0    12    1  2785  170.0  72.6    0\n",
       "1     1  男     4.16   7.70  225.0    11    7  3133  174.0  52.7    0\n",
       "2     1  男     4.09   8.45  218.0    14    1  3901  169.0  46.5    0\n",
       "3     1  男     4.21   8.05  206.0    13    1  4946  183.0  79.7    0\n",
       "4     1  男     3.44   7.52  210.0    13    9  3538  171.0  54.7    0\n",
       "..   .. ..      ...    ...    ...   ...  ...   ...    ...   ...  ...\n",
       "472  17  男     4.23   8.27  208.0    10    0  4647  176.0  69.5    0\n",
       "473  17  男     5.19   9.55  210.0    15    6  7042  177.0  76.0    0\n",
       "474  17  男     3.25   7.50  252.0    13   13  5755  181.0  65.0    0\n",
       "475  17  男     4.39   7.81  208.0    14   11  5688  172.0  51.7    0\n",
       "476  17  男     0.00   0.00    0.0     0    0     0    0.0   0.0    0\n",
       "\n",
       "[477 rows x 11 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "male\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1ba5268e",
   "metadata": {},
   "outputs": [],
   "source": [
    "rule = rule.replace(\"'\",\".\",regex=True)\n",
    "rule = rule.replace('\"',\"\",regex=True)\n",
    "rule = rule.astype(float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "44ee4063",
   "metadata": {},
   "outputs": [],
   "source": [
    "female[['女体前屈','女仰卧','女肺活量','BMI']] = female[['女体前屈','女仰卧','女肺活量','BMI']].astype(float)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "54749b0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "班级           int64\n",
       "性别          object\n",
       "男1000米跑    float64\n",
       "男50米跑      float64\n",
       "男跳远        float64\n",
       "男体前屈         int64\n",
       "男引体          int64\n",
       "男肺活量         int64\n",
       "身高         float64\n",
       "体重         float64\n",
       "BMI          int64\n",
       "dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "班级          int64\n",
       "性别         object\n",
       "女800米跑    float64\n",
       "女50米跑     float64\n",
       "女跳远       float64\n",
       "女体前屈      float64\n",
       "女仰卧       float64\n",
       "女肺活量      float64\n",
       "身高        float64\n",
       "体重        float64\n",
       "BMI       float64\n",
       "dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "男肺活量     成绩    float64\n",
       "         分数    float64\n",
       "女肺活量     成绩    float64\n",
       "         分数    float64\n",
       "男50米跑    成绩    float64\n",
       "         分数    float64\n",
       "女50米跑    成绩    float64\n",
       "         分数    float64\n",
       "男体前屈     成绩    float64\n",
       "         分数    float64\n",
       "女体前屈     成绩    float64\n",
       "         分数    float64\n",
       "男跳远      成绩    float64\n",
       "         分数    float64\n",
       "女跳远      成绩    float64\n",
       "         分数    float64\n",
       "男引体      成绩    float64\n",
       "         分数    float64\n",
       "女仰卧      成绩    float64\n",
       "         分数    float64\n",
       "男1000米跑  成绩    float64\n",
       "         分数    float64\n",
       "女800米跑   成绩    float64\n",
       "         分数    float64\n",
       "dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(male.dtypes,female.dtypes,rule.dtypes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f4507f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对体测成绩进行分数转换，跑步类（越小越好）；跳远、体前屈（越大越好）\n",
    "\n",
    "# 使用map、apply、transform方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89465093",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f14ba4ff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2aa3a438",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de6ff774",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
